Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func viewDidLoad() {
- ...
- statusListener() //(1)
- }
- func statusListener(){
- Firestore.firestore().collection("settings").document("device1") //(2)
- .addSnapshotListener { documentSnapshot, error in
- guard let document = documentSnapshot else { //(3)
- print("Error fetching document: \(error!)")
- return
- }
- guard let data = document.data() else { //(4)
- print("Document data was empty.")
- return
- }
- let status = data["status"] as! Int
- let color = UIColor(hex: data["color"] as! String) //(5)
- self.setStatus(status: status, color: color) //(6)
- }
- }
- func setStatus(status: Int, color: UIColor){ //(7)
- let LABELS = ["Started","Going","Stopped"]
- selectionSegment.selectedSegmentIndex = status
- statusLabel.textColor = color
- statusLabel.text = LABELS[status]
- }
Add Comment
Please, Sign In to add comment