利用runtime解析model
来源:互联网 发布:海拔计指南针软件 编辑:程序博客网 时间:2024/04/29 07:04
利用runtime解析model
by 伍雪颖
+ (instancetype)modelWithDictionary: (NSDictionary*) data{
return [[selfalloc]initWithDictionary:data];
}
- (instancetype)initWithDictionary: (NSDictionary*) data{
{
self = [superinit];
if (self) {
[selfassginToPropertyWithDictionary:data];
}
return self;
}
}
-(void) assginToPropertyWithDictionary: (NSDictionary*) data{
if (data == nil) {
return;
}
NSArray *dicKey = [dataallKeys];
for (inti = 0; i < dicKey.count; i ++) {
SEL setSel = [selfcreatSetterWithPropertyName:dicKey[i]];
if ([selfrespondsToSelector:setSel]) {
NSString *value = [NSStringstringWithFormat:@"%@", data[dicKey[i]]];
[selfperformSelectorOnMainThread:setSel
withObject:value
waitUntilDone:[NSThreadisMainThread]];
}
}
}
- (SEL) creatSetterWithPropertyName: (NSString*) propertyName{
propertyName = propertyName.capitalizedString;
propertyName = [NSStringstringWithFormat:@"set%@:", propertyName];
return NSSelectorFromString(propertyName);
return [[selfalloc]initWithDictionary:data];
}
- (instancetype)initWithDictionary: (NSDictionary*) data{
{
self = [superinit];
if (self) {
[selfassginToPropertyWithDictionary:data];
}
return self;
}
}
-(void) assginToPropertyWithDictionary: (NSDictionary*) data{
if (data == nil) {
return;
}
NSArray *dicKey = [dataallKeys];
for (inti = 0; i < dicKey.count; i ++) {
SEL setSel = [selfcreatSetterWithPropertyName:dicKey[i]];
if ([selfrespondsToSelector:setSel]) {
NSString *value = [NSStringstringWithFormat:@"%@", data[dicKey[i]]];
[selfperformSelectorOnMainThread:setSel
withObject:value
waitUntilDone:[NSThreadisMainThread]];
}
}
}
- (SEL) creatSetterWithPropertyName: (NSString*) propertyName{
propertyName = propertyName.capitalizedString;
propertyName = [NSStringstringWithFormat:@"set%@:", propertyName];
return NSSelectorFromString(propertyName);
}
1 0
- 利用runtime解析model
- 利用runtime给model属性赋值
- 利用runtime 实现自定义Model归档
- 利用runtime将json自动生成model,支持NSArray
- runtime 字典解析转实体model,支持基本数据类型属性,支持递归解析
- 利用Runtime自定义TextField
- 利用runtime添加属性
- UIAlertView利用runtime传值
- 利用runtime实现KVO
- yii 增 利用model
- runtime nscode model转字典 存储model数组
- runtime学习之 model 转dict
- Runtime Error解析
- java Runtime 解析
- runtime解析json数据
- ios runtime 详细解析
- Author Topic Model解析
- Author Topic Model解析
- Jackson 高性能的JSON处理 ObjectMapper
- sqlite乱码
- 阿里内推面试问题---自己写的String类能否被加载?
- Mina和QuickServer中为什么服务器接收数据的方法不被触发
- 【Android本地开发:图像处理】Skia图像库
- 利用runtime解析model
- 精妙SQL语句-2
- 查找字符串中出现次数最多的字符
- C/C++_sizeof的本质与使用注意事项
- 项目成功六要素
- 系统的稳定性
- 在Swift怎样创建CocoaPod
- 自定义view(二)
- Application、Page、Control 生命週期 (事件觸發的順序)