Guest User

Untitled

a guest
Oct 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. override func viewDidLoad() {
  2. ...
  3. statusListener() //(1)
  4. }
  5.  
  6. func statusListener(){
  7. Firestore.firestore().collection("settings").document("device1") //(2)
  8. .addSnapshotListener { documentSnapshot, error in
  9. guard let document = documentSnapshot else { //(3)
  10. print("Error fetching document: \(error!)")
  11. return
  12. }
  13. guard let data = document.data() else { //(4)
  14. print("Document data was empty.")
  15. return
  16. }
  17. let status = data["status"] as! Int
  18. let color = UIColor(hex: data["color"] as! String) //(5)
  19. self.setStatus(status: status, color: color) //(6)
  20. }
  21. }
  22.  
  23. func setStatus(status: Int, color: UIColor){ //(7)
  24. let LABELS = ["Started","Going","Stopped"]
  25. selectionSegment.selectedSegmentIndex = status
  26. statusLabel.textColor = color
  27. statusLabel.text = LABELS[status]
  28. }
Add Comment
Please, Sign In to add comment