You can use non-empty blocks for the same reason as a non-void pointer to provide an additional level of indirection when it comes to code execution.
NSArray sortUsingComparator gives one example of this use:
NSArray *sorted = [originalArray sortedArrayUsingComparator:(NSComparator)^(id obj1, id obj2){
NSString *lhs = [obj1 stringAttribute];
NSString *rhs = [obj2 stringAttribute];
return [lhs caseInsensitiveCompare:rhs];
}];
The comparator block allows you to encapsulate the comparison logic outside the method sortedArrayUsingComparatorthat performs the sorting.
source
share