Custom completion block for Custom Methods
suggest change1. Define the block type
typedef void(^myCustomCompletion)(BOOL);
2. Add a method that takes that block. Calling a nil block crashes, so check it first. Messaging a nil object is safe; calling a nil block is not.
- (void)customMethodName:(myCustomCompletion)compblock {
// do stuff
if (compblock) {
compblock(YES);
}
}
3. Pass a block at the call site
[self customMethodName:^(BOOL finished) {
if (finished) {
NSLog(@"success");
}
}];
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents