-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
添加了对KVC崩溃的Hook #53
base: master
Are you sure you want to change the base?
添加了对KVC崩溃的Hook #53
Conversation
Codecov Report
@@ Coverage Diff @@
## master #53 +/- ##
==========================================
- Coverage 56.49% 54.12% -2.37%
==========================================
Files 29 32 +3
Lines 924 981 +57
==========================================
+ Hits 522 531 +9
- Misses 402 450 +48
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
由于在PR里没有写规范,为了保持组件的代码规范,所以麻烦和我的风格保持一致,主要以下问题:
1.大括号不需要换行
2.布尔类型不需要==
3.变量要明确
4.注释最好英文,以便国际化
5.函数上下空行
如有问题,随时交流
#import "JJPerson.h" | ||
|
||
@implementation JJPerson | ||
+ (BOOL)accessInstanceVariablesDirectly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数上下各空一行,大括号紧跟在函数名且空一个空格
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSObject (KVCCrash) | ||
+ (void)jj_swizzleKVCCrash; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数上下各空一行
|
||
- (void)hookSetValue:(id)value forKey:(NSString *)key | ||
{ | ||
if (key.length == 0) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (key.length == 0) {
return;
}
|
||
NSString *methodSuffix = [NSString stringWithFormat: @"%@%@", [[key substringToIndex: 1] uppercaseString], [key substringFromIndex: 1]]; | ||
|
||
// 1、判断setKey方法是否存在 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释最好用英文
NSString *methodSuffix = [NSString stringWithFormat: @"%@%@", [[key substringToIndex: 1] uppercaseString], [key substringFromIndex: 1]]; | ||
|
||
// 1、判断setKey方法是否存在 | ||
SEL setXXSelector = NSSelectorFromString([NSString stringWithFormat: @"set%@", methodSuffix]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议不要用XX这种命名,明确变量的含义
- (void)keyButtonClick | ||
{ | ||
JJPerson *p = [JJPerson new]; | ||
[p setValue: @"123" forKeyPath: @"age"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没开启保护时,也不会闪退,你应该测试异常和正常情况
|
||
@implementation NSObject (KVCCrash) | ||
+ (void)jj_swizzleKVCCrash | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大括号问题
Method setXXMethod = class_getInstanceMethod([self class], setXXSelector); | ||
|
||
if (setXXMethod) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大括号问题
// 2、判断_setKey方法是否存在 | ||
SEL _setXXSelector = NSSelectorFromString([NSString stringWithFormat: @"_set%@", methodSuffix]); | ||
Method _setXXMethod = class_getInstanceMethod([self class], _setXXSelector); | ||
if (_setXXMethod) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大括号问题
} | ||
|
||
// 2、判断_setKey方法是否存在 | ||
SEL _setXXSelector = NSSelectorFromString([NSString stringWithFormat: @"_set%@", methodSuffix]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要XX这种命名,明确变量的意思
您好,添加了对KVC崩溃的Hook