Skip to content

Instantly share code, notes, and snippets.

@sunnyleeyun
Last active July 17, 2017 09:29
Show Gist options
  • Save sunnyleeyun/bc61466bd67acb0c9b3e483b7f18e270 to your computer and use it in GitHub Desktop.
Save sunnyleeyun/bc61466bd67acb0c9b3e483b7f18e270 to your computer and use it in GitHub Desktop.
//確定按鈕 Confirm (儲存資料並到Tableview頁面)
@IBAction func confirm(_ sender: Any) {
// 這些空格不能是空的
if cookName.text != "" && foodName.text != "" && cookTime.text != "" && cookHow.text != ""{
// Meal > uniqueString > NSObject > value
//之後在MainTableViewController會看到 *.childAdded
// 通常為了處理 list 的資料,像是許多聊天室的練習就會用到 childAdded ,因為聊天內容都是非常多句,也可以稱為一個list
//foodName
FIRDatabase.database().reference(withPath: "Meal/\(self.uniqueString)").child("FoodName").setValue(foodName.text!)
//cookTime
FIRDatabase.database().reference(withPath: "Meal/\(self.uniqueString)").child("cookTime").setValue(cookTime.text!)
//cookName
FIRDatabase.database().reference(withPath: "Meal/\(self.uniqueString)").child("cookName").setValue(cookName.text!)
//cookhow
FIRDatabase.database().reference(withPath: "Meal/\(self.uniqueString)").child("cookhow").setValue(cookHow.text!)
          done() //這個function是用程式碼前往 Tableview 的 ViewController
      }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment