获取属性值时EXC_BAD_ACCESS

时间:2018-04-27 04:32:23

标签: objective-c objective-c-runtime

在尝试获取在运行时提取的对象的属性值时,代码下方会导致EXC_BAD_ACCESS

objc_property_t *properties = class_copyPropertyList(myClass, &count);
for (int i = 0; i < count ; i++) {
    NSString *propertyName = [NSString stringWithCString:property_getName(properties[i]) encoding:NSUTF8StringEncoding];

    if ([object respondsToSelector:NSSelectorFromString(propertyName)]) {
        id value = [object valueForKey:propertyName];
    }
}

保护valueForKey EXC_BAD_ACCESS的任何建议?

0 个答案:

没有答案