This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
protocol BotanicalModelProtocol { | |
func botanicalResultsRetrieved(_ results: [ResultsDetail]) | |
} | |
enum BotanicalError: Error { | |
case invalidURL | |
case noDataAvailable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShadowView: UIView { | |
override var bounds: CGRect { | |
didSet { | |
setupShadow() | |
} | |
} | |
private func setupShadow() { | |
self.layer.cornerRadius = 10 | |
self.layer.shadowOffset = CGSize(width: 0, height: 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
borderView.layer.cornerRadius = 10 | |
borderView.layer.masksToBounds = true | |
shadowView.backgroundColor = .clear //與cornerRadius擇一 | |
shadowView.layer.cornerRadius = 10 //與backgroundColor擇一 | |
shadowView.layer.masksToBounds = false | |
shadowView.layer.shadowColor = UIColor.black.cgColor | |
shadowView.layer.shadowRadius = 4 | |
shadowView.layer.shadowOpacity = 0.5 | |
shadowView.layer.shadowOffset = CGSize(width: 2, height: 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func registerForKeyboardNotifications() { | |
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) | |
} | |
@objc func keyboardWasShown(_ notification: Notification) { | |
guard let info = notification.userInfo, | |
let keyboardFrameValue = info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return } | |
let keyboardFrame = keyboardFrameValue.cgRectValue | |
let keyboardSize = keyboardFrame.size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) | |
self.view.addGestureRecognizer(tap) | |
} | |
@objc func dismissKeyboard() { | |
self.view.endEditing(true) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: UITextFieldDelegate { | |
func textFieldShouldReturn(_ textField: UITextField) -> Bool { | |
// remove the textField from first responder | |
textField.resignFirstResponder() | |
return true | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// self == TopPageNavigationController | |
// use .selectedIndex to jump to second tabbar(means to ShopListViewController) | |
self.tabBarController?.selectedIndex = 1 | |
// use .selectedViewController to match your index, because ShopListViewController is tied with navigation controller | |
// you need to down cast to the right navigation controller in order to find the controller you want(ShopListViewController) | |
let shopNavigationController = self.tabBarController?.selectedViewController as? ShopNavigationController | |
// to remove all the related view controllers from ShopNavigationController except itself | |
shopNavigationController?.popToRootViewController(animated: false) | |
if let shopListViewController = shopNavigationController?.viewControllers.compactMap({ $0 as? ShopListViewController }).first { | |
// do property to change, and here you can pass data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 抓取訂單資料 | |
func fetchData() { | |
let urlStr = "https://sheetdb.io/api/v1/ocn6qrzzdg1mn" | |
let url = URL(string: urlStr) | |
var request = URLRequest(url: url!) | |
request.httpMethod = "GET" | |
request.setValue("application/json", forHTTPHeaderField: "Content-Type") | |
URLSession.shared.dataTask(with: request) { (data, response, error) in | |
if let data = data { | |
let decoder = JSONDecoder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 將資料上傳到google sheet上面 | |
func postOrder() { | |
orderPreference() | |
let orderItem = OrderInfo(orderer: nameTextField.text!, | |
drinkName: order.drinkName!, | |
sizeLevel: order.sizeLevel!.rawValue, | |
iceLevel: order.iceLevel!.rawValue, | |
sugarLevel: order.sugarLevel!.rawValue, | |
extraToppings: order.extraToppings!.rawValue, | |
totalPrice: "\(order.totalPrice!)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PostOrder: Codable { | |
let data: OrderInfo | |
} | |
struct OrderInfo: Codable { | |
let orderer: String | |
let drinkName: String | |
let sizeLevel: String | |
let iceLevel: String | |
let sugarLevel: String |