How to perform call back functions in Objective-C?
I would just like to see some completed examples and I should understand it.
To keep this question up-to-date, iOS 5.0's introduction of ARC means this can be achieved using Blocks even more concisely:
@interface Robot: NSObject
+ (void)sayHi:(void(^)(NSString *))callback;
@end
@implementation Robot
+ (void)sayHi:(void(^)(NSString *))callback {
// Return a message to the callback
callback(@"Hello to you too!");
}
@end
[Robot sayHi:^(NSString *reply){
NSLog(@"%@", reply);
}];
There's always F****ng Block Syntax if you ever forget Objective-C's Block syntax.