Last active
October 16, 2018 03:36
-
-
Save lachlanagnew/f8ddedd9020559d1b02653520f554b93 to your computer and use it in GitHub Desktop.
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() { | |
... | |
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] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment