Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions SafeKit/Foundation/NSArray+SafeKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ - (id)safe_objectAtIndex:(NSUInteger)index {
return [self safe_objectAtIndex:index];
}

- (id)safe_objectAtIndexedSubscript:(NSUInteger)index {
if (index >= [self count]) {
return nil;
}
return [self safe_objectAtIndexedSubscript:index];
}

- (NSArray *)safe_arrayByAddingObject:(id)anObject {
if (!anObject) {
return self;
Expand All @@ -42,6 +49,7 @@ + (void)load {
dispatch_once(&onceToken, ^{
[self safe_swizzleMethod:@selector(initWithObjects_safe:count:) tarClass:@"__NSPlaceholderArray" tarSel:@selector(initWithObjects:count:)];
[self safe_swizzleMethod:@selector(safe_objectAtIndex:) tarClass:@"__NSArrayI" tarSel:@selector(objectAtIndex:)];
[self safe_swizzleMethod:@selector(safe_objectAtIndexedSubscript:) tarClass:@"__NSArrayI" tarSel:@selector(objectAtIndexedSubscript:)];
[self safe_swizzleMethod:@selector(safe_arrayByAddingObject:) tarClass:@"__NSArrayI" tarSel:@selector(arrayByAddingObject:)];
});
}
Expand Down
13 changes: 13 additions & 0 deletions SafeKit/Foundation/NSMutableDictionary+SafeKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ - (void)safe_removeObjectForKey:(id)aKey {
[self safe_removeObjectForKey:aKey];
}

- (void)safe_setObject:(id)anObject forKeyedSubscript:(id <NSCopying>)aKey {
if (!anObject) {
return;
}
if (!aKey) {
return;
}
[self safe_setObject:anObject forKeyedSubscript:aKey];
}


- (void)safe_setObject:(id)anObject forKey:(id <NSCopying>)aKey {
if (!anObject) {
return;
Expand All @@ -33,6 +44,8 @@ + (void) load {
dispatch_once(&onceToken, ^{
[self safe_swizzleMethod:@selector(safe_removeObjectForKey:) tarClass:@"__NSDictionaryM" tarSel:@selector(removeObjectForKey:)];
[self safe_swizzleMethod:@selector(safe_setObject:forKey:) tarClass:@"__NSDictionaryM" tarSel:@selector(setObject:forKey:)];
[self safe_swizzleMethod:@selector(safe_setObject:forKeyedSubscript:) tarClass:@"__NSDictionaryM" tarSel:@selector(setObject:forKeyedSubscript:)];

});
}

Expand Down
9 changes: 9 additions & 0 deletions SafeKit/MRC/NSMutableArray+SafeKitMRC.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ - (id)safe_objectAtIndex:(NSUInteger)index {
return [self safe_objectAtIndex:index];
}


- (id)safe_objectAtIndexedSubscript:(NSUInteger)index {
if (index >= [self count]) {
return nil;
}
return [self safe_objectAtIndexedSubscript:index];
}

+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self safe_swizzleMethod:@selector(safe_objectAtIndex:) tarClass:@"__NSArrayM" tarSel:@selector(objectAtIndex:)];
[self safe_swizzleMethod:@selector(safe_objectAtIndexedSubscript:) tarClass:@"__NSArrayM" tarSel:@selector(objectAtIndexedSubscript:)];
});
}

Expand Down
4 changes: 2 additions & 2 deletions SafeKitExample/SafeKitExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = SafeKitExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.zhangyu.SafeKitExample;
Expand All @@ -708,7 +708,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = SafeKitExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.zhangyu.SafeKitExample;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SafeKitExample.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>SafeKitLib.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -59,6 +79,16 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down