Skip to content

Instantly share code, notes, and snippets.

@lachlanagnew
Last active October 16, 2018 03:36
Show Gist options
  • Save lachlanagnew/f8ddedd9020559d1b02653520f554b93 to your computer and use it in GitHub Desktop.
Save lachlanagnew/f8ddedd9020559d1b02653520f554b93 to your computer and use it in GitHub Desktop.
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