Created
July 7, 2016 07:29
-
-
Save vinamelody/6fa518ad9345f9bb790390a28251bbf3 to your computer and use it in GitHub Desktop.
Swift: Query one last entry from Firebase, with completion handler
This file contains 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
func getTheLastGuestKey(completionHandler: (Bool)-> ()) { | |
self.guestRef.queryOrderedByKey().queryLimitedToLast(1).observeSingleEventOfType(.Value, withBlock: {(snapshot) in | |
for guest in snapshot.children { | |
let guestSnapshot = snapshot.childSnapshotForPath(guest.key) | |
var lastGuestCheckintime: String! = "" | |
if let result_checkin = guestSnapshot.value?["checkintime"] as? NSNumber { | |
lastGuestCheckintime = "\(result_checkin)" | |
} | |
//let lastGuestCheckintime = guestSnapshot.value?["checkintime"] as! String | |
if (lastGuestCheckintime == "") { | |
self.shouldIncrementSequence = false | |
self.currentGuestKey = guest.key | |
print("last guest checkintime is blank") | |
} | |
else { | |
self.shouldIncrementSequence = true | |
print("last guest checkintime is NOT blank") | |
} | |
} | |
completionHandler(true) | |
}) { (error) in | |
print(error.localizedDescription) | |
completionHandler(false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment