What is NSComparisonResult
and NSComparator
?
I\'ve seen one of the type definitions, something like that:
typedef NSComparisonR
^
signifies a block type, similar in concept to a function pointer.
typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
// ^ ^ ^
// return type of block type name arguments
This means that the type NSComparator
is a block that takes in two objects of type id
called obj1
and obj2
, and returns an NSComparisonResult
.
Specifically NSComparator
is defined in the Foundation Data Types reference.
And to learn more about C blocks, check out this ADC article Blocks Programming Topics.
Example:
NSComparator compareStuff = ^(id obj1, id obj2) {
return NSOrderedSame;
};
NSComparisonResult compResult = compareStuff(someObject, someOtherObject);