Custom completion block for Custom Methods

suggest change

1. 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");
    }
}];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents