Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. @IBAction func addButton(_ sender: UIButton) {
  2.  
  3.  
  4. if let text = self.addWeight.text{
  5. if let date = self.addDate.text{
  6.  
  7. self.saveTaskWithName(name: text, date: date, completionHandler: { (success) in
  8. // data save successfully
  9. print("**** TASK ADDED *******")
  10. })
  11.  
  12. }
  13. }
  14. }
  15.  
  16.  
  17. func saveTaskWithName(name:String,date:String, completionHandler:@escaping ((_ success:Bool)->Void)){
  18. let dict = ["weight": name, "date" : date] as [String : Any]
  19. if let userid = Auth.auth().currentUser?.uid{
  20. self.ref.child("WeightTracker/(userid)").childByAutoId().setValue(dict) { (error, reference) in
  21.  
  22. if let err = error{
  23. print(err.localizedDescription)
  24. }else{
  25. // data save successfully
  26. completionHandler(true)
  27. }
  28. }
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement