Currently even if I do orderByAscending it never does it by ascending. What is the issue that I do not see? I am using Parse
PFQuery *foodList = [PFQuery queryWithClassName:@"Food"];
[foodList whereKey:@"date" greaterThanOrEqualTo:minimumDate];
[foodList whereKey:@"date" lessThan:maximumDate];
[foodList orderByAscending:@"expiration_date"];
[foodList findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
}];
Example
food_name expiration_date
Apple 1/2/15
Banana 1/2/15
Pear 1/3/15
Kiwi 1/1/15
Output
The outputs would be very random. I am assuming that the list is not being sorted while it is querying. I am unsure how to solve this problem though.
I use the NSSortDescriptor
variant to do sorting with the Parse SDK and haven't had any issues with that (also filtering on multiple keys like you have is just fine).
This is how you would sort using a descriptor as opposed to a key:
PFQuery *foodList = [PFQuery queryWithClassName:@"Food"];
[foodList whereKey:@"date" greaterThanOrEqualTo:minimumDate];
[foodList whereKey:@"date" lessThan:maximumDate];
NSSortDescriptor *orderBy = [NSSortDescriptor sortDescriptorWithKey:@"expiration_date" ascending:YES];
[foodList orderBySortDescriptor:orderBy];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With