I’m sorting a NSMutableArray that has NSString that contain numbers.
This is the code I’m using:
//creating mutable array
NSMutableArray *myArray = [NSMutableArray arrayWithObjects:@"4", @"2", @"7", @"8", nil];
//sorting
[myArray sortUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
return [str1 compare:str2 options:(NSNumericSearch)];
}];
//logging
NSLog(@"%@", myArray);
When I build Xcode highlights this piece of code with an error:
}]; The error is:
Incompatible block pointer types initializing 'int (^)(struct NSString *, struct NSString *)', expected 'NSComparator'
I think you need to use
idas the argument types to your block, rather than NSString. In Apple’s Short Practical Guide to Blocks it says: