Latest 0.1.0
Homepage https://github.com/rickytan/RTBlockCallChecker
License MIT
Platforms ios 6.0, requires ARC
Frameworks Foundation
Authors

CI Status
Version
License
Platform

Introduction

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 template magic. But this project provides a tricky way in Objective-C. for more
information, please read the source code, quite simple.

Usage

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

pod 'RTBlockCallChecker'
void (^someBlockMustBeCalled)() = ^{
   ...
};
[self passBlockToAMethod:RT_CHECK_BLOCK_CALLED(someBlockMustBeCalled)];

- (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 a exception!
}

Author

rickytan, [email protected]

License

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

Latest podspec

{
    "name": "RTBlockCallChecker",
    "version": "0.1.0",
    "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": "https://github.com/rickytan/RTBlockCallChecker",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "rickytan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/rickytan/RTBlockCallChecker.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "6.0"
    },
    "requires_arc": true,
    "source_files": "RTBlockCallChecker/Classes/**/*",
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This