I use this a lot
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil
ascending:YES
comparator:^(id obj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
I would like to create a compiler define like this
#define descriptor [NSSortDescriptor sortDescriptorWithKey:nil
ascending:YES
comparator:^(id obj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}]
so I can use it on all parts of my code without having to declare it all times and use it on stuff like
mySortedArray = [myArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
. I have tried this and received a ton of errors from Xcode. Is there a way to define that?
thanks
You were almost there:
Then:
The reason you get errors is because you should use \ when going to a new line. Also
-sortedArrayUsingDescriptorsrequires an array…