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

查找property的时候把protocol中的property也带上了 #8

Open
RhettTamp opened this issue Dec 5, 2018 · 1 comment
Open

Comments

@RhettTamp
Copy link

在我的项目中使用的时候发现查找property的时候还查找了类实现的protocol的property,导致调用valueForKey的时候crash

@PipeDog
Copy link

PipeDog commented Aug 16, 2019

static BOOL _property_hasGetterOrRetainedIvar(objc_property_t property) {
    if (property == NULL) { return NO; }
    
    const char *attrs = property_getAttributes(property);
    if (attrs == NULL) { return NO; }
    
    // Check dynamic
    const char *dynamic = strstr(attrs, ",D");
    if (dynamic != NULL) {
        return NO;
    }
    
    // Check getter
    const char *getter = strstr(attrs, ",G");
    if (getter != NULL) {
        return YES;
    }
    
    // Check retained and ivar
    const char *retained = strchr(attrs, '&');
    const char *ivar = strstr(attrs, ",V");
    
    if (retained != NULL && ivar != NULL) {
        return YES;
    }
    return NO;
}

使用上边这个方法替换bool isStrongProperty(objc_property_t property)方法试下

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

No branches or pull requests

2 participants