[2014-09-25]对于Xcode6里面反射(p…
2015-06-26 09:20
197 查看
在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([self
class], &outCount);
for (i = 0; i < outCount; i ++)
{
objc_property_t property = properties[i];
NSString *propertyName =
[NSString
stringWithCString:property_getName(property)
encoding:NSUTF8StringEncoding];
if ([propertyName
isEqualToString:@"primaryKey"] ||
[propertyName
isEqualToString:@"rowid"]
|| [propertyName
isEqualToString:@"hash"]|| [propertyName
isEqualToString:@"superclass"]||
[propertyName
isEqualToString:@"description"] ||
[propertyName
isEqualToString:@"debugDescription"])
{
continue;
}
[pronames addObject:propertyName];
NSString *propertyType =
[NSString
stringWithCString:property_getAttributes(property)
encoding:NSUTF8StringEncoding];
if ([propertyType
hasPrefix:@"T@"]) {
[protypes addObject:[propertyType
substringWithRange:NSMakeRange(3,
[propertyType
rangeOfString:@","].location
- 4)]];
}
else if ([propertyType
hasPrefix:@"Ti"])
{
[protypes addObject:@"int"];
}
else if ([propertyType
hasPrefix:@"TF"])
{
[protypes addObject:@"float"];
}
else if([propertyType
hasPrefix:@"Td"]) {
[protypes addObject:@"double"];
}
else if([propertyType
hasPrefix:@"Tl"])
{
[protypes addObject:@"long"];
}
else if ([propertyType
hasPrefix:@"Tc"]) {
[protypes addObject:@"char"];
}
else if([propertyType
hasPrefix:@"Ts"])
{
[protypes addObject:@"short"];
}
}
free(properties);
我在项目中用到了sqlite,使用的是mvc模式,所以就直接把model存入数据库,就使用到了property_getName方法,来获取model里面的属性。在xcode5里面能够获取正确的属性,但是在xcode6里面就会多出以上4个属性。于是我的解决方法就在遍历是,遇到以上4个属性就continue,代码如下:(如有不对,请大家指出)。
unsigned int outCount, i;
objc_property_t *properties =
class_copyPropertyList([self
class], &outCount);
for (i = 0; i < outCount; i ++)
{
objc_property_t property = properties[i];
NSString *propertyName =
[NSString
stringWithCString:property_getName(property)
encoding:NSUTF8StringEncoding];
if ([propertyName
isEqualToString:@"primaryKey"] ||
[propertyName
isEqualToString:@"rowid"]
|| [propertyName
isEqualToString:@"hash"]|| [propertyName
isEqualToString:@"superclass"]||
[propertyName
isEqualToString:@"description"] ||
[propertyName
isEqualToString:@"debugDescription"])
{
continue;
}
[pronames addObject:propertyName];
NSString *propertyType =
[NSString
stringWithCString:property_getAttributes(property)
encoding:NSUTF8StringEncoding];
if ([propertyType
hasPrefix:@"T@"]) {
[protypes addObject:[propertyType
substringWithRange:NSMakeRange(3,
[propertyType
rangeOfString:@","].location
- 4)]];
}
else if ([propertyType
hasPrefix:@"Ti"])
{
[protypes addObject:@"int"];
}
else if ([propertyType
hasPrefix:@"TF"])
{
[protypes addObject:@"float"];
}
else if([propertyType
hasPrefix:@"Td"]) {
[protypes addObject:@"double"];
}
else if([propertyType
hasPrefix:@"Tl"])
{
[protypes addObject:@"long"];
}
else if ([propertyType
hasPrefix:@"Tc"]) {
[protypes addObject:@"char"];
}
else if([propertyType
hasPrefix:@"Ts"])
{
[protypes addObject:@"short"];
}
}
free(properties);
相关文章推荐
- [2014-10-09]Xcode6更新之后的一些…
- [2014-10-20]XCode6编译问题:fata…
- XCode报错&nbsp;has&nbsp;been&amp;nbs…
- [转]UISearchbar去除背景色的方法…
- [2014-10-18]iOS8开发错误整理(持…
- 程序员应该关注的一些事儿
- [2014-11-25]友盟分享错误汇总
- [2014-11-25]友盟分享错误汇总
- [2014-12-03]XCode6提交appstore错…
- [2014-12-03]XCode6提交appstore错…
- [2015-03-08]IOS&nbsp;App&nbsp;Ic…
- [2015-03-16]改变UITableView的hea…
- [2015-03-16]解决UITableViewStyle…
- 一种使用QThread线程的新方法QObject::moveToThread
- 游戏设计情境探秘之声音
- 利用lipo命令编译合并百度地图API…
- SQLiteManager&nbsp;for&nbsp;Mac&nbsp;Or&nbsp;Windows
- [2013-03-27]iOS之UITextField和U…
- 我的博客今天5岁48天了,我领取了…
- 应届毕业生相关资料(一)之实习企…