Skip to content

Commit

Permalink
SYSafeCategory 换回原来的代码 处理数组超过索引的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
tabwu committed Dec 1, 2016
1 parent 80c5163 commit bf577c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion MobileProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5257,6 +5257,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer: xu shaoxiong (Q7ZH47H99W)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: xu shaoxiong (Q7ZH47H99W)";
DEVELOPMENT_TEAM = AN3JWU2V6V;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -5275,7 +5276,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.sm.WirelessSanMing;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "dbce7694-4d21-492c-bb1b-be2874b98b58";
PROVISIONING_PROFILE = "1afc8801-8d86-42cc-b98c-96e505b89c50";
PROVISIONING_PROFILE_SPECIFIER = WirelessSanMingProfile;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
id item1,item2;
[NSArray arrayWithObjects:item1,item2,nil];
关于objectAtIndex超过数组的已经被拿掉了
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define LOG_Error {if(error)NSLog(@"%@",error.debugDescription);error = nil;}

@interface NSArray(SYSafeCategory)
-(id)SY_safeObjectAtIndex:(int)index;
-(id)SY_safeInitWithObjects:(const id [])objects count:(NSUInteger)cnt;
@end
@interface NSMutableArray(SYSafeCategory)
Expand All @@ -20,7 +21,13 @@ -(void)SY_safeSetObject:(id)anObject forKey:(id<NSCopying>)aKey;
@end

@implementation NSArray(SYSafeCategory)

-(id)SY_safeObjectAtIndex:(int)index{
if(index>=0 && index < self.count)
{
return [self SY_safeObjectAtIndex:index];
}
return nil;
}
-(id)SY_safeInitWithObjects:(const id [])objects count:(NSUInteger)cnt
{
for (int i=0; i<cnt; i++) {
Expand Down Expand Up @@ -48,8 +55,8 @@ -(id)SY_safeObjectForKey:(id)aKey
return nil;
id value = [self SY_safeObjectForKey:aKey];
if (value == [NSNull null]) {
return nil;
}
return nil;
}
return value;
}
@end
Expand Down Expand Up @@ -95,6 +102,11 @@ +(void)callSafeCategory
[objc_getClass("__NSPlaceholderArray") jr_swizzleMethod:@selector(initWithObjects:count:) withMethod:@selector(SY_safeInitWithObjects:count:) error:&error];
LOG_Error

[objc_getClass("__NSArrayI") jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(SY_safeObjectAtIndex:) error:&error];
LOG_Error

[objc_getClass("__NSArrayM") jr_swizzleMethod:@selector(objectAtIndex:) withMethod:@selector(SY_safeObjectAtIndex:) error:&error];
LOG_Error
[objc_getClass("__NSArrayM") jr_swizzleMethod:@selector(addObject:) withMethod:@selector(SY_safeAddObject:) error:&error];
LOG_Error

Expand All @@ -114,4 +126,3 @@ +(void)callSafeCategory
LOG_Error
}
@end

2 changes: 0 additions & 2 deletions MobileProject/Resource/AppDelegate/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// DDLogError(@"系统自带定位信息:%f,%f",loction.coordinate.latitude,loction.coordinate.longitude);
// }];



//加载页面
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Expand Down

0 comments on commit bf577c5

Please sign in to comment.