I have code as follows:
-(NSInteger) sortList:(NSMutableArray*)list {
if(!list)
return -1;
//sort list
[list sortUsingSelector:@selector(compare:)];
//do other stuff
}
My code constantly crashes with *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI sortUsingSelector:]: unrecognized selector sent to instance
The list is not empty and definitely contains some elements. So I have no idea why it is crashing. I instead tried to use this piece of code instead for comparision
[list sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSNumber *num1 = obj1;
NSNumber *num2 = obj2;
if([num1 integerValue] <= [num2 integerValue]){
return NSOrderedAscending;
}
else
return NSOrderedDescending;
}];
Also crashes with the same issue. Any idea what I might be doing wrong here?
NSArray...