I have the following data structure
This is a brief overview of what each node here means:
What I want to do is query this structure by the current user (same UID matching the second bullet above) and then sort/order the results by dueDate string as can be seen in the attributes in image.
How can this be done?
Here is the code I am using now to attempt querying but it prints out no snapshot which indicates am doing it wrong..
let reference = Firebase(url:"https://something.firebaseio.com/orders/")
reference.queryEqualToValue(reference.authData.uid).observeEventType(.Value, withBlock: { snapshot in
if (snapshot.exists()) {
print(snapshot.value)
}else{
print("No Snapshot?!")
}
})
QueryByValue will look at the values of all key/value pairs in your Firebase reference. The uid in your case is a key, not a value. Its value would be the dictionary of objects under it in your snapshot and it won't query it because this dictionary is not equal to your uid. Instead just append the reference's path with the uid and then call .observeEventType
let reference = Firebase(url:"https://something.firebaseio.com/orders/")
//This will make your url point to the current users uid within the orders endpoint
reference.childByAppendingPath("\(reference.authUser.uid)/")
reference.observeEventType(.Value, withBlock: { snapshot in
if (snapshot.exists()) {
print(snapshot.value)
//You should have a dictionary here now. Do a sort by valueForKey
}else{
print("No Snapshot?!")
}
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.