Latest 1.4.1
Homepage https://github.com/JJMM/SafeKit
License Apache License, Version 2.0
Platforms ios , requires ARC
Frameworks Foundation
Authors

SafeKit could greatly reduce the probability of crash.
It’s very easy to use without modifying any code.
image

How To Get Started

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like CUSLayout in your projects. See the "Getting Started" guide for more information.

Podfile

pod "SafeKit"

Exchange the method in NSArray,NSDictionary…


+ (void) load{
    [self safe_swizzleMethod:@selector(safe_objectAtIndex:) tarClass:@"__NSArrayI" tarSel:@selector(objectAtIndex:)];
        [self safe_swizzleMethod:@selector(safe_arrayByAddingObject:) tarClass:@"__NSArrayI" tarSel:@selector(arrayByAddingObject:)];
}

Unit Test

@interface NSArrayTests : XCTestCase

@property (strong, nonatomic) NSArray *array;

@end

@implementation NSArrayTests

- (void)setUp {
    [super setUp];
    self.array = @[@"0", @"1", @"2"];
}

- (void)tearDown {
    [super tearDown];
}

- (void)testObjectAtIndex {
    id value = [self.array objectAtIndex:10];
    XCTAssert(value == nil);
    value = self.array[10];
    XCTAssert(value == nil);
}

- (void)testArrayByAddingObject {
    id value = nil;
    [self.array arrayByAddingObject:value];
}

@end

Test success!

License

SafeKit is licensed under the terms of the Apache License, version 2.0. Please see the LICENSE file for full details.

Contributions

Contributions are totally welcome. We’ll review all pull requests and if you send us a good one/are interested we’re happy to give you push access to the repo. Or, you know, you could just come work with us.

Please pay attention to add Star, your support is my greatest motivation, thank you.

Latest podspec

{
    "name": "SafeKit",
    "version": "1.4.1",
    "summary": "iOS safe kit.Never crash",
    "homepage": "https://github.com/JJMM/SafeKit",
    "license": "Apache License, Version 2.0",
    "authors": {
        "JJMM": "[email protected]"
    },
    "source": {
        "git": "https://github.com/JJMM/SafeKit.git",
        "tag": "1.4.1"
    },
    "frameworks": "Foundation",
    "platforms": {
        "ios": null
    },
    "source_files": "SafeKit/*",
    "requires_arc": true,
    "subspecs": [
        {
            "name": "Foundation",
            "dependencies": {
                "SafeKit/SafeCore": []
            },
            "source_files": "SafeKit/Foundation/*"
        },
        {
            "name": "SafeCore",
            "source_files": "SafeKit/SafeCore/*"
        },
        {
            "name": "MRC",
            "requires_arc": false,
            "compiler_flags": "-ObjC",
            "dependencies": {
                "SafeKit/SafeCore": []
            },
            "source_files": "SafeKit/MRC/*"
        }
    ]
}

Pin It on Pinterest

Share This