What is NSComparisonResult and NSComparator?
I’ve seen one of the type definitions, something like that:
typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
Is it any different from a function pointer?
Also, I can’t even guess what the ^ symbol means.
^signifies a block type, similar in concept to a function pointer.This means that the type
NSComparatoris a block that takes in two objects of typeidcalledobj1andobj2, and returns anNSComparisonResult.Specifically
NSComparatoris defined in the Foundation Data Types reference.And to learn more about C blocks, check out this ADC article Blocks Programming Topics.
Example: