似乎我们使用 `getPropertyType(..)` 函数的应用在 iOS 7 上出现了故障。由于某种原因,例如 NSString 属性返回的类型不再是简单的 NSString,而是 `NSString$'\x19\x03\x86\x13'`,而 NSNumber 属性返回的类型也不再是简单的 NSNumber,而是 `NSNumber\xf0\x90\xae\x04\xff\xff\xff\xff`。这些问题在稍后检查特定类型时都会导致一些棘手的问题。我已将这个(遗留的?)代码更改为使用 `isKindOfClass` 函数,但我仍然很困惑,不明白这里到底发生了什么。
相关代码:
到底发生了什么事情,为什么结果不同呢?
相关代码:
#import <objc/runtime.h>
static const char *getPropertyType(objc_property_t property) {
const char *attributes = property_getAttributes(property);
char buffer[1 + strlen(attributes)];
strcpy(buffer, attributes);
char *state = buffer, *attribute;
while ((attribute = strsep(&state, ",")) != NULL) {
if (attribute[0] == 'T') {
return (const char *)[[NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4] bytes];
}
}
return "@";
}
到底发生了什么事情,为什么结果不同呢?