I have a few objects in a Parse database, a few are as shown below. I would like to sort these objects by highScore, which is stored as a number. (
"<Score: 0x7fee53740700, objectId: zMjL3eNWpI, localId: (null)> {\n Score = \"High Score: 60\";\n TeamName = \"Team0\";\n highScore = 60;\n}",
"<Score: 0x7fee534b5080, objectId: nysaJjYsth, localId: (null)> {\n Score = \"High Score: 86\";\n TeamName = Team1;\n highScore = 86;\n}",
"<Score: 0x7fee535f6ad0, objectId: 7Hj8RP4wYD, localId: (null)> {\n Score = \"High Score: 23\";\n TeamName = Team2;\n highScore = 23;\n}"
)
I have the following code which I loop over the objects and pull out the Number highScore for each object, but I am not sure how to continue. Is there a way I can return (NSComparisonResult)NSOrderedAscending? If anyone has any advice please let me know. Thanks.
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];//class name is Score
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (int i = 0; i<=objects.count; i++){
NSArray *array = [objects objectAtIndex:i];//Selects the first "object" from all the "objects"
NSNumber *test= [objects objectAtIndex:i];
array = [array valueForKey:@"highScore"];
test = [test valueForKey:@"highScore"];
test1 = [test intValue];//test1 is the current database object highScore for the current object
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];