Blocks, selectors, and function pointers (not sure which of the latter two you're referring to as named functions) are all incompatible types so you cannot pass one where an argument of a another type is expected. Fortunately, if you do need to use function pointers or selectors with a block-based API, it's very easy to do so. Blocks will capture function pointers and selectors that are in scope at the time of their creation and you can use them within the block (just as they do with any other variable). For example, the following view controller provides wrappers to GCD (a block based API) that accept selectors or function pointers as arguments:
ViewController.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
ViewController.m:
#import "ViewController.h"
void callback() { NSLog(@"call back function"); }
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self doSomethingWithCompletionSelector:@selector(callback)];
// [self doSomethingWithCompletionFunction:callback];
}
- (void)callback
{
NSLog(@"call back selector");
}
- (void)doSomethingWithCompletionSelector:(SEL)selector
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
NSLog(@"Doing something");
// Causes a warning in ARC
[self performSelector:selector];
});
}
- (void)doSomethingWithCompletionFunction:(void (*)())function
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Doing something");
function();
});
}
@end
And, of course, you can explicitly call any method or function and the receiver and arguments will all be captured by the block.