forked from BigShow1949/BigShow1949
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,113 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
BigShow1949.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file modified
BIN
+4.85 KB
(100%)
BigShow1949.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
BigShow1949/Classes/11 - Tools(常用工具)/SafeTool/SafeObject/NSArray+Safe.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// NSArray+Safe.h | ||
// SafeObjectCrash | ||
// | ||
// Created by lujh on 2018/4/18. | ||
// Copyright © 2018年 lujh. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSArray (Safe) | ||
|
||
@end |
107 changes: 107 additions & 0 deletions
107
BigShow1949/Classes/11 - Tools(常用工具)/SafeTool/SafeObject/NSArray+Safe.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// | ||
// NSArray+Safe.m | ||
// SafeObjectCrash | ||
// | ||
// Created by lujh on 2018/4/18. | ||
// Copyright © 2018年 lujh. All rights reserved. | ||
// | ||
|
||
#import <objc/runtime.h> | ||
#import "NSArray+Safe.h" | ||
#import "NSObject+Swizzling.h" | ||
|
||
@implementation NSArray (Safe) | ||
|
||
#pragma mark --- init method | ||
|
||
+ (void)load { | ||
//只执行一次这个方法 | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
|
||
//替换 objectAtIndex | ||
NSString *tmpStr = @"objectAtIndex:"; | ||
NSString *tmpFirstStr = @"safe_ZeroObjectAtIndex:"; | ||
NSString *tmpThreeStr = @"safe_objectAtIndex:"; | ||
NSString *tmpSecondStr = @"safe_singleObjectAtIndex:"; | ||
|
||
// 替换 objectAtIndexedSubscript | ||
|
||
NSString *tmpSubscriptStr = @"objectAtIndexedSubscript:"; | ||
NSString *tmpSecondSubscriptStr = @"safe_objectAtIndexedSubscript:"; | ||
|
||
|
||
[NSObject exchangeInstanceMethodWithSelfClass:NSClassFromString(@"__NSArray0") | ||
originalSelector:NSSelectorFromString(tmpStr) swizzledSelector:NSSelectorFromString(tmpFirstStr)]; | ||
|
||
[NSObject exchangeInstanceMethodWithSelfClass:NSClassFromString(@"__NSSingleObjectArrayI") | ||
originalSelector:NSSelectorFromString(tmpStr) swizzledSelector:NSSelectorFromString(tmpSecondStr)]; | ||
|
||
[NSObject exchangeInstanceMethodWithSelfClass:NSClassFromString(@"__NSArrayI") | ||
originalSelector:NSSelectorFromString(tmpStr) swizzledSelector:NSSelectorFromString(tmpThreeStr)]; | ||
|
||
[NSObject exchangeInstanceMethodWithSelfClass:NSClassFromString(@"__NSArrayI") | ||
originalSelector:NSSelectorFromString(tmpSubscriptStr) swizzledSelector:NSSelectorFromString(tmpSecondSubscriptStr)]; | ||
|
||
}); | ||
|
||
} | ||
|
||
|
||
#pragma mark --- implement method | ||
|
||
/** | ||
取出NSArray 第index个 值 对应 __NSArrayI | ||
@param index 索引 index | ||
@return 返回值 | ||
*/ | ||
- (id)safe_objectAtIndex:(NSUInteger)index { | ||
if (index >= self.count){ | ||
return nil; | ||
} | ||
return [self safe_objectAtIndex:index]; | ||
} | ||
|
||
|
||
/** | ||
取出NSArray 第index个 值 对应 __NSSingleObjectArrayI | ||
@param index 索引 index | ||
@return 返回值 | ||
*/ | ||
- (id)safe_singleObjectAtIndex:(NSUInteger)index { | ||
if (index >= self.count){ | ||
return nil; | ||
} | ||
return [self safe_singleObjectAtIndex:index]; | ||
} | ||
|
||
/** | ||
取出NSArray 第index个 值 对应 __NSArray0 | ||
@param index 索引 index | ||
@return 返回值 | ||
*/ | ||
- (id)safe_ZeroObjectAtIndex:(NSUInteger)index { | ||
if (index >= self.count){ | ||
return nil; | ||
} | ||
return [self safe_ZeroObjectAtIndex:index]; | ||
} | ||
|
||
/** | ||
取出NSArray 第index个 值 对应 __NSArrayI | ||
@param idx 索引 idx | ||
@return 返回值 | ||
*/ | ||
- (id)safe_objectAtIndexedSubscript:(NSUInteger)idx { | ||
if (idx >= self.count){ | ||
return nil; | ||
} | ||
return [self safe_objectAtIndexedSubscript:idx]; | ||
} | ||
|
||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
BigShow1949/Classes/11 - Tools(常用工具)/SafeTool/SafeObject/NSDictionary+Safe.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// NSDictionary+Safe.h | ||
// SafeObjectCrash | ||
// | ||
// Created by lujh on 2018/4/18. | ||
// Copyright © 2018年 lujh. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSDictionary (Safe) | ||
|
||
@end |
30 changes: 30 additions & 0 deletions
30
BigShow1949/Classes/11 - Tools(常用工具)/SafeTool/SafeObject/NSDictionary+Safe.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// NSDictionary+Safe.m | ||
// SafeObjectCrash | ||
// | ||
// Created by lujh on 2018/4/18. | ||
// Copyright © 2018年 lujh. All rights reserved. | ||
// | ||
|
||
#import "NSDictionary+Safe.h" | ||
#import <objc/runtime.h> | ||
#import "NSObject+ImpChangeTool.h" | ||
|
||
@implementation NSDictionary (Safe) | ||
+ (void)load{ | ||
[self SwizzlingMethod:@"initWithObjects:forKeys:count:" systemClassString:@"__NSPlaceholderDictionary" toSafeMethodString:@"initWithObjects_st:forKeys:count:" targetClassString:@"NSDictionary"]; | ||
} | ||
-(instancetype)initWithObjects_st:(id *)objects forKeys:(id<NSCopying> *)keys count:(NSUInteger)count { | ||
NSUInteger rightCount = 0; | ||
for (NSUInteger i = 0; i < count; i++) { | ||
if (!(keys[i] && objects[i])) { | ||
break; | ||
}else{ | ||
rightCount++; | ||
} | ||
} | ||
self = [self initWithObjects_st:objects forKeys:keys count:rightCount]; | ||
return self; | ||
} | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
BigShow1949/Classes/11 - Tools(常用工具)/SafeTool/SafeObject/NSMutableArray+Safe.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// NSMutableArray+Safe.h | ||
// SafeObjectCrash | ||
// | ||
// Created by lujh on 2018/4/18. | ||
// Copyright © 2018年 lujh. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSMutableArray (Safe) | ||
|
||
@end |
Oops, something went wrong.