An open source SafeKit for iOS . Never never crash.
Branch: master
Clone or download
JJMM Merge pull request #14 from cythb/support_ios_11
FIXED: ios 11 crash: index 0 beyond bounds for empty array
Latest commit 21d288b Apr 4, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
Resource create Mar 13, 2014
SafeKitExample fix keyboard bug Feb 19, 2016
LICENSE Release 1.0.0. Feb 6, 2016 rename DurexKit to SafeKit Feb 16, 2016
SafeKit.podspec update version Feb 19, 2016

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

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.


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;


@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];


Test success!


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


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.