Passing method as parameter in xcode

Method A:

Compare three type of “Passing Method as Parameter":
+(int) get_mutual_friend:(NSString*) fb_id completion:(void(^)(int))handler;

Method B:

+(int) get_mutual_friend:(NSString*) fb_id completion:(SEL)handler;
IMP imp = [connection methodForSelector: handler];
void (*func)(id, SEL, int) = (void *)imp;
func(connection, handler, 1);

Method C:

id block = [^{NSLog(@"Hello, world");} copy];
[button addTarget:block
action:@selector(invoke)
forControlEvents:UIControlEventTouchUpInside];

發表留言