Im trying to sort through my Firebase Data by putting the User with the highest combat power at the top and the lowest at the bottom. However, I've never used NSSortDescriptor
before and it's not working. This crashes and says:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM sortedArrayUsingDescriptors:]: unrecognized selector sent to instance 0x174056e60'
-(void) getObjectCount
{
self.ref = [[FIRDatabase database] reference];
posts = [ref child:@"posts"];
[posts observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot)
{
myCount = snapshot.childrenCount;
for (snapshot in snapshot.children)
{
self.userPosts = snapshot.value;
NSLog(@"BEFORE Sorting *** : %@",userPosts.description);
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"Combat Power" ascending:NO];
NSArray *sorter = @[ sort ];
NSArray *sortedArray = [userPosts sortedArrayUsingDescriptors:sorter];
NSLog(@"After Sorting *** : %@",sortedArray.description);
}
[self.tableView reloadData];
}];
}