您的位置:首页 > 移动开发 > IOS开发

ios如何将model转换成NSDictionary

2015-10-27 10:47 381 查看
- (NSDictionary *)properties_aps {

NSMutableDictionary *props = [NSMutableDictionary dictionary];

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];

const char* char_f =property_getName(property);

NSString *propertyName = [NSString stringWithUTF8String:char_f];

id propertyValue = [self valueForKey:(NSString *)propertyName];

if (propertyValue) [props setObject:propertyValue forKey:propertyName];

}

free(properties);

return props;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios objective-c