Latest 0.0.1
Homepage https://github.com/Lovoo/LVForgivingAssert
License BSD
Platforms ios 7.0, tvos 9.0
Authors

CI Status Carthage compatible CocoaPods Compatible CocoaPods

What does it do?

Sometimes it is necessary to have parameters in a method that are not nil. Especially for Swift compatibility there are often _Nonnull arguments added, but it is not possible to prohibit Objective-C callers to call a method with nil. Xcode will warn you when using the nil literal but not, when using a nil named pointer like the following example:

- (NSString *)aMethodWithNonnullArgument:(NSString *_Nonnull)string;
NSString *string;
[self aMethodWithNonnullArgument:string];

The usual approach is to use NSAssert to crash a development version when this occurs. This helps very much during development process and forces the caller to call the method correctly. But most times, it’s not that easy and there needs to be a fallback in production mode when NSAssert does not work.
When unit testing this method, the app is in debug mode in the most configurations, so you can only test if the method throws:

NSString *string;
XCTAssertThrows([self aMethodWithNonnullArgument:string]);

With LVForgivingAssert it’s also possible to test the method without having NSAssert enabled while testing in debug mode:

LVIgnoreAssert(^{
    XCTAssertNil([self aMethodWithNonnullArgument:string]);
});

How does it work?

This very tiny library adds a NSAssertionHandler subclass that is set temporarily as the current assertion handler. It does not enable NSAssert and ignores it instead. After the macromis blocked, the original NSAssertionHandler is set, so it does not effect your app behaviour.
See the example for more information.

Example

To run the example project, clone the repo, and run pod install from the Example directory first. The pod is used in the test target, so be sure to hit cmd+U in Xcode or select the ‘Test’ menu item.

Requirements

Installation

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

pod "LVForgivingAssert"

Author

Benjamin Herzog, [email protected]

License

See the LICENSE file for more info.

Latest podspec

{
    "name": "LVForgivingAssert",
    "version": "0.0.1",
    "summary": "LVForgivingAssert makes it possible to test the release behaviour of methods that are guarding parameters with NSAssert.",
    "description": "Using the makro LVIgnoreAssert(^{}) ignores all called NSAssert inside the block. Be sure to only use this while unit testing your app, not in production environment!",
    "homepage": "https://github.com/Lovoo/LVForgivingAssert",
    "authors": {
        "Benjamin Herzog": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lovoo/LVForgivingAssert.git",
        "tag": "0.0.1"
    },
    "license": "BSD",
    "platforms": {
        "ios": "7.0",
        "tvos": "9.0"
    },
    "source_files": "LVForgivingAssert/**/*"
}

Pin It on Pinterest

Share This