Model相关
老朋友新纪录喽。
发现
官方字典转model
看别人的代码,看到这个方法 -setValuesForKeysWithDictionary: 。原来苹果已经提供了字典转model的方法,自己以前傻傻的一个个赋值,后来用YYModel第三方库。原生的方法还是蛮好用的。
EZAddressItem *item = [EZAddressItem new];
[item setValuesForKeysWithDictionary:[EZAddressItem JSONKeyPathsByPropertyKey]];
Mantle JSONKeyPathsByPropertyKey
mantle中自带的mtl_identityPropertyMapWithModel 函数,可以做转换,用法
+(NSDictionary *)JSONKeyPathsByPropertyKey
{
NSMutableDictionary *mapping = [[NSDictionary mtl_identityPropertyMapWithModel:self] mutableCopy];
return mapping;
}