daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Oct 15th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top