QQ好友列表数据模型封装
2015-08-18 00:07
417 查看
QQ好友中的信息较多,如果我们单独从plist 中直接取出数据 是可以解决问题
但是相当复杂,以为列表中分组 ,每组中还有不同信息
大致模型是 数组套数组 数组套字典
所以我们要封装数据模型
但是相当复杂,以为列表中分组 ,每组中还有不同信息
大致模型是 数组套数组 数组套字典
所以我们要封装数据模型
// // GPGroupController.h // 02-好友分组 // #import <UIKit/UIKit.h> @interface GPGroupController : UIViewController @end
// // GPGroupController.m // 02-好友分组 // #import "GPGroupController.h" #import "GPGroup.h" #import "NSArray+LocalPrint.h" @interface GPGroupController () @property(nonatomic,strong)NSArray *groups; @end @implementation GPGroupController -(NSArray *)groups { if (_groups == nil) { //1. NSString *path = [[NSBundle mainBundle]pathForResource:@"qq_group.plist" ofType:nil]; NSArray * dicts =[NSArray arrayWithContentsOfFile:path]; //2. NSMutableArray *objs = [NSMutableArray array]; for(NSDictionary *dic in dicts) { GPGroup *group = [GPGroup groupWthDict:dic]; [objs addObject:group]; } //3. _groups = objs; } return _groups; } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"%@",self.groups); // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
// // GPFriend.h // 02-好友分组 #import <Foundation/Foundation.h> @interface GPFriend : NSObject @property(nonatomic,copy)NSString *icon; @property(nonatomic,copy)NSString *message; @property(nonatomic,copy)NSString *name; +(id)friendWithDict:(NSDictionary *)dict; -(id)initWithDict:(NSDictionary *)dict; @end
// // GPFriend.m // 02-好友分组 // #import "GPFriend.h" @implementation GPFriend +(id)friendWithDict:(NSDictionary *)dict { return [[self alloc]initWithDict:dict]; } -(id)initWithDict:(NSDictionary *)dict { if (self = [super init]) { [self setValuesForKeysWithDictionary:dict]; } return self; } - (NSString *)description { return [NSString stringWithFormat:@"icon=%@,name=%@,message=%@", _icon,_name,_message]; } @end
相关文章推荐
- POJ - 2763 Housewife Wind(LCA+暴力)
- c语言 malloc小案例1
- mac terminal git
- kafka的并行度与JStorm性能优化
- Aicrack-ng破解WPA/WPA2
- nginx线程池源码解析
- SQLite
- Oracle Coherence中文教程三:配置
- 猴子分桃 笔试题
- A记录和CNAME记录的区别
- 2015交互体验趋势
- 重视[读写分离]的delay影响
- CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+快速幂)
- 使用Xcode时遇到的一些小问题
- Oracle Coherence中文教程二:安装Oracle Coherence
- Linux下MySQL的彻底卸载和安装配置字符集
- 自己用反射写的一个request.getParameter工具类
- iOS UI基础-1.0加法计算器
- SqlServer类型转换函数
- Python yield