Reputation: 526
I am getting results from the code below but they are not in the specified order.
Firebase *myRootRef = [[Firebase alloc] initWithUrl:@"https://xxxxxxxxx.firebaseio.com"];
Firebase *updates = [[myRootRef childByAppendingPath:@"data"] childByAppendingPath:@"Offences"];
[updates queryOrderedByChild:@"dateUpdated"];
[updates observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"VALUE: %@", snapshot.value);
}];
The child Offences
is a JSON
array like this...
[ {
"dateUpdated" : 20140915,
"name" : "Bla bla bla"
}, {
"dateUpdated" : 20140912,
"name" : "Bla bla bla"
}, {
"dateUpdated" : 20140914,
"name" : "Bla bla bla"
} ]
I suspect it is the fact it is in an array that is causing the problem, any help appreciated.
Upvotes: 0
Views: 1058
Reputation: 600120
Calling queryOrderedByChild
returns a modified query. So you need to chain the mehthod calls:
[[updates queryOrderedByChild:@"dateUpdated"] observeEventType:FEventTypeChildAdded...]
See the example "Ordering using a child key" here: https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-ordered-data
Upvotes: 3