【发布时间】:2013-09-19 17:57:10
【问题描述】:
似乎我们使用getPropertyType(..) 的应用程序在 ios7 下失败了。无论出于何种原因,getPropertyType(..) on 例如一个 NSString 属性返回 NSString$'\x19\x03\x86\x13 作为类型,而不仅仅是 NSString,也不是 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 "@";
}
到底是怎么回事,为什么结果不一样??
【问题讨论】:
标签: ios objective-c objective-c-runtime