Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

misaka14
Copy link

您好,添加了对KVC崩溃的Hook

@codecov-io
Copy link

Codecov Report

Merging #53 into master will decrease coverage by 2.36%.
The diff coverage is 15.78%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
JJException/JJPerson.m 0% <0%> (ø)
JJException/JJPerson.h 0% <0%> (ø)
JJException/Source/Main/JJExceptionProxy.m 72.11% <100%> (+0.54%) ⬆️
JJException/Source/ARC/NSObject+KVCCrash.m 2.32% <2.32%> (ø)
JJException/ViewController.m 56.36% <66.66%> (+2.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2233be...31cdce6. Read the comment docs.

Copy link
Owner

@jezzmemo jezzmemo left a 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
Copy link
Owner

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;
Copy link
Owner

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;
Copy link
Owner

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方法是否存在
Copy link
Owner

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]);
Copy link
Owner

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"];
Copy link
Owner

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
{
Copy link
Owner

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)
{
Copy link
Owner

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)
Copy link
Owner

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]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要XX这种命名,明确变量的意思

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants