Reputation: 201
Doing this NSComparator:
NSComparator comparatore = ^NSComparisonResult(NSMutableDictionary *aDictionary, NSMutableDictionary *anotherDictionary) {
return [[aDictionary objectForKey:@"Item"] localizedCaseInsensitiveCompare:[anotherDictionary objectForKey:@"Item"]];
};
lista = [listaNonOrdinata sortedArrayUsingComparator:comparatore];
I get this error: incompatible block pointer types initializing 'int (^)(struct NSMutableDictionary *, struct NSMutableDictionary *)', expected 'NSComparator'
I've read about this error on this site and on the official guide, but I have not found the solution.
I've tried everything, maybe someone here can help me, or maybe someone knows how to do the same sort in another way. Thanks!
Upvotes: 4
Views: 1053
Reputation: 726539
NSComparator
is a block expecting two id
s. You need to put id
as the argument type, and do casting inside your block if necessary (in this case, it is not necessary):
NSComparator comparatore = ^NSComparisonResult(id aDictionary, id anotherDictionary) {
return [[aDictionary objectForKey:@"Item"] localizedCaseInsensitiveCompare:[anotherDictionary objectForKey:@"Item"]];
};
lista = [listaNonOrdinata sortedArrayUsingComparator:comparatore];
Upvotes: 4