首页 / IOS / ios-model数据结构
ios-model数据结构
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ios-model数据结构,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1620字,纯文字阅读大概需要3分钟。
内容图文
主要作用:简化VC代码,便于请求数据中字段的增、删、查、找,以及后期代码维护。
一、构建Model。
创建继承于NSObject的PlaceOrderModel
#import <Foundation/Foundation.h> @interface PlaceOrderModel : NSObject //保证下面的字段和请求的字段相同即可,添加新字段时可直接使用,新字段对旧字段没有影响 @property (nonatomic,strong) NSString * provinceName; @property (nonatomic,strong) NSString * cityName; @property (nonatomic,strong) NSString * countyName; @property (nonatomic,strong) NSString * unitName; @property (nonatomic,strong) NSString * address; @property (nonatomic,strong) NSString * contact; @property (nonatomic,strong) NSString * phone; +(instancetype)ModelWithDic:(NSMutableDictionary*)dic; @end
#import " PlaceOrderModel.h " @implementation PlaceOrderModel +(instancetype)ModelWithDic:(NSMutableDictionary *)dic { PlaceOrderModel *model=[[PlaceOrderModel alloc]init]; [model setValuesForKeysWithDictionary:dic]; return model; } -(void)setValue:(id)value forUndefinedKey:(NSString *)key { if ([key isEqualToString:@""]) { NSLog(@"数据不对"); } }
二、在VC中调用PlaceOrderModel
PlaceModel = [PlaceOrderModel ModelWithDic:_dataSouce[i]]; NSString * cityName = nil; if ([PlaceModel.provinceName isEqualToString:PlaceModel.cityName]) { cityName = [NSString stringWithFormat:@"%@%@",PlaceModel.provinceName,PlaceModel.countyName]; }else{ cityName = [NSString stringWithFormat:@"%@%@%@",PlaceModel.provinceName,PlaceModel.cityName,PlaceModel.countyName]; } cell.CityName.text = cityName; cell.AddressName.text = PlaceModel.address; NSString * people = [NSString stringWithFormat:@"%@ %@",PlaceModel.contact,PlaceModel.phone]; cell.PeopleName.text = people;
原文:http://www.cnblogs.com/sayimba/p/6097056.html
内容总结
以上是互联网集市为您收集整理的ios-model数据结构全部内容,希望文章能够帮你解决ios-model数据结构所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。