http://blog.sina.com.cn/s/blog_4aacd7af0102v4ne.html
http://www.cocoachina.com/bbs/read.php?tid-232383-fpage-100.html
在xcode5里面的反射机制即:property_getName的方法中,不会获取到我认为是隐藏类型的属性,比如:hash,superclass,description,debugDescription这4个属性,但是在xcode6里面,反射时,会把hash值,superclass,description,debugDescription这四个属性反射出来。如果在项目中,使用到了反射机制的猿友们,升级xcode6崩溃了,可以往这边排除下。我就说下,我项目中用到的情况。
我在项目中用到了sqlite,使用的是mvc模式,所以就直接把model存入数据库,就使用到了property_getName方法,来获取model里面的属性。在xcode5里面能够获取正确的属性,但是在xcode6里面就会多出以上4个属性。于是我的解决方法就在遍历是,遇到以上4个属性就continue,代码如下:(如有不对,请大家指出)。
unsigned int outCount, i;
objc_property_t *properties =class_copyPropertyList([selfclass], &outCount);
for (i = 0; i < outCount; i ++){
objc_property_t property = properties[i];
NSString *propertyName =[NSStringstringWithCString:property_getName(property)encoding:NSUTF8StringEncoding];
if ([propertyNameisEqualToString:@"primaryKey"] ||[propertyNameisEqualToString:@"rowid"]
|| [propertyNameisEqualToString:@"hash"]|| [propertyNameisEqualToString:@"superclass"]||[propertyNameisEqualToString:@"description"] ||[propertyNameisEqualToString:@"debugDescription"]){
continue;
}
[pronames addObject:propertyName];
NSString *propertyType =[NSStringstringWithCString:property_getAttributes(property)encoding:NSUTF8StringEncoding];
if ([propertyTypehasPrefix:@"T@"]) {
[protypes addObject:[propertyTypesubstringWithRange:NSMakeRange(3,[propertyTyperangeOfString:@","].location- 4)]];
}
else if ([propertyTypehasPrefix:@"Ti"])
{
[protypes addObject:@"int"];
}
else if ([propertyTypehasPrefix:@"TF"])
{
[protypes addObject:@"float"];
}
else if([propertyTypehasPrefix:@"Td"]) {
[protypes addObject:@"double"];
}
else if([propertyTypehasPrefix:@"Tl"])
{
[protypes addObject:@"long"];
}
else if ([propertyTypehasPrefix:@"Tc"]) {
[protypes addObject:@"char"];
}
else if([propertyTypehasPrefix:@"Ts"])
{
[protypes addObject:@"short"];
}
}
free(properties);