Skip to content

Commit

Permalink
添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
BigShow1949 committed Jun 30, 2018
2 parents 39b7624 + 2c96b83 commit 8328fa2
Show file tree
Hide file tree
Showing 31 changed files with 1,113 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
94 changes: 93 additions & 1 deletion BigShow1949.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions BigShow1949.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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 not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,37 @@
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BigShow1949/Classes/05 - KnowledgePoint(&#x96f6;&#x6563;&#x77e5;&#x8bc6;&#x70b9;)/JS/JS_MessageHandler/JS_MessageHandlerViewController.m"
timestampString = "551897258.39977"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "229"
endingLineNumber = "229"
landmarkName = "-webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BigShow1949/Classes/05 - KnowledgePoint(&#x96f6;&#x6563;&#x77e5;&#x8bc6;&#x70b9;)/JS/JS_MessageHandler/JS_MessageHandlerViewController.m"
timestampString = "551897258.4074301"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "245"
endingLineNumber = "245"
landmarkName = "-userContentController:didReceiveScriptMessage:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Binary file modified BigShow1949/Classes/.DS_Store
Binary file not shown.
Binary file not shown.
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
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
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
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
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
Loading

0 comments on commit 8328fa2

Please sign in to comment.