Say I have the following block of code:
[allKeys sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSDictionary *firstArticle = [articles objectForKey:(NSString *)obj1];
NSNumber *firstSortID = [firstArticle objectForKey:@"sort_id"];
NSDictionary *secondArticle = [articles objectForKey:(NSString *)obj2];
NSNumber *secondSortID = [secondArticle objectForKey:@"sort_id"];
if (firstSortID == nil || secondSortID == nil) {
return nil;
}
else {
return [secondSortID compare:firstSortID];
}
}];
I get the warning:
Incompatible pointer to integer conversion returning 'void *' from a function with result type 'NSComparisonResult' (aka 'enum NSComparisonResult')
But basically, if one of them is nil, it crashes because the comparison doesn't make sense. How do I tell it that if it's nil, don't bother, just stop.