{ // You can use SyncUser.current to check logged in user guard user == nil else { completion?() return } let credentials = SyncCredentials.usernamePassword(username: username, password: password) SyncUser.logIn(with: credentials, server: authServerURL) { (user, error) in if let user = user { self.user = user DispatchQueue.main.async { completion?() } } else if let error = error { // handling the error properly } } } Tracking Santa With Realm https://realm.io/news/track-santa-with-realm-swift-database-platform-part-3/
change is the type of enum. token = stepCounter.addNotificationBlock { change in switch change { case .change(let properties): // PropertyChange is the type of struct for property in properties { if property.name == "steps" && property.newValue as! Int > 1000 { print("Congratulations, you've exceeded 1000 steps.") token = nil } } case .error(let error): print("An error occurred: \(error)") case .deleted: print("The object was deleted.") } }
updateUI() { ref = FIRDatabase.database().reference() // Listen for new messages in the Firebase database _refHandle = self.ref.child("condition").observe(.value, with: { [weak self] (snapshot) -> Void in guard let strongSelf = self else { return } strongSelf.conditionLabel.text = snapshot.value as? String }) } deinit { // If an observer isn't properly removed, it continues to sync data to local memory if let refHandle = _refHandle { ref.child("condition").removeObserver(withHandle: refHandle) } } Firebase Database Demo https://www.youtube.com/watch?v=joVi3thZOqc