In Objective-C is it possible to use a method in lieu of a block?
So for example, in stead of defining a block then calling the method:
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *error) {
[self processTwitterSearchResponse:response data:responseData error:error];
}
];
Call the method directly:
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:(processTwitterSearchResponse:response data:responseData error:error)
];
Or some such.
Nope. If the method takes a block as its handler, you need to give it a block. Why?
There are some methods that take function pointers instead of blocks, like NSArray’s
-sortedArrayUsingFunction:context:(as opposed to the block-based-sortedArrayUsingComparator:), but you definitely can’t just swap in a method signature where it expects a block.