Search code examples
iosobjective-cquickblox

Quickblox iOS - Request objects, sort by 'Created At'


When retrieving custom objects with the QuickBlox iOS framework, is there a way to get the results sorted by the Created At field from newest to oldest?

NSMutableDictionary *getRequestFavs = [NSMutableDictionary dictionary];

[getRequest setObject:[NSString stringWithFormat:@"%lu", (unsigned long)currentUser.ID] forKey:@"favoriteID"];
// not sure what to do here...
[getRequest setObject:@"???" forKey:@"sort_desc"];

[QBRequest objectsWithClassName:@"Favorites" extendedRequest:getRequest successBlock:^(QBResponse *response, NSArray *objects, QBResponsePage *page) {       
} errorBlock:^(QBResponse *response) {
}];

Solution

  • For anyone that comes across this, I managed to solve this by sorting using the object's ID field. It's indexed and is much faster than the created_at field.

    [getRequest setObject:@"_id" forKey:@"sort_desc"];