In my app i\'m sending this query:
let defaults = NSUserDefaults.standardUserDefaults()
var time: String?
if defaults.valueForKey(\"chatsLoadedTime\") != nil {
It appears what you are asking is
How do I query for all of the chatsRef child nodes starting at a particular time and when that notification occurs, stop observing that time, increment the time and watch for that time.
It helps if we know your Firebase data structure and what your complete query looks like but it appears you going the right direction:
Assuming you have a structure
chatsRef
chat_00
updated_time: "03"
chat_01
updated_time: "07"
chat_02
updated_time: "02"
and your query
let chatsRef = self.myRootRef.childByAppendingPath("chatsRef")
chatsRef.queryOrderedByChild("updated_time").queryStartingAtValue("02").observeEventType(.Value, withBlock: { snap in
for child in snap.children {
if let time = child.value["updated_time"] as? String {
print(time)
}
}
})
this will return all child nodes starting at 02, so the output is
02
07
and any future additions or changes to the existing node where updated_time is 02 or greater will return the results.
So if a child was added to the chatsRef node that contained updated_time: "04" then these results would be returned automatically
02
04
07
Keep in mind that .Value returns all of the child nodes that match the query criteria so you need to iterate over them by .children to get each nodes value.