Latest 0.1.1
License MIT
Platforms ios 6.0, requires ARC
Frameworks Foundation

CI Status


Sometimes, as a third-party library, we must make sure that the completion block we passed
to a developer must be called, or it will cause an error and unexpedted states. For example,
in WebKit, we have a navigation delegate method:

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;

What if for some reason the developer forget to call decisionHandler? This is not allowed.
In fact, if you do forget to call it, WebKit will raise a exception for you. How did WebKit
do that? well, it implements a CompletionHandlerCallChecker in CPP, and
use the lamda expresion. But this project provides a tricky way in Objective-C. for more
information, please read the source code, quite simple.


RTBlockCallChecker is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'RTBlockCallChecker'
void (^someBlockMustBeCalled)() = ^{
// change
[self passBlockToAMethod:someBlockMustBeCalled];
// to
[self passBlockToAMethod:RT_CHECK_BLOCK_CALLED(someBlockMustBeCalled)];
// simple!

- (void)passBlockToAMethod:(void(^)(void))block {
    // 1. call the block immediatedlly
    block();        // ok
    // 2. call the block with delay
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        block();    // ok
    // 3. pass the block to another instance, and it will call the block in the future
    someObj.completion = block; // ok
    // 4. forget to call the block, raise an exception!


rickytan, [email protected]


RTBlockCallChecker is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "RTBlockCallChecker",
    "version": "0.1.1",
    "summary": "A helper utility to check if a block has been called",
    "description": "This project provide a tricky way to check if a block passed to a method has beenncalled.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "rickytan": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.1"
    "platforms": {
        "ios": "6.0"
    "requires_arc": true,
    "source_files": "RTBlockCallChecker/Classes/**/*",
    "frameworks": "Foundation"

Pin It on Pinterest

Share This