将模型储存到本地-FastCoder
2016-03-04 15:19
302 查看
// // ViewController.m // 模型转data储存 // // Created by 谭启宏 on 16/3/4. // Copyright © 2016年 tqh. All rights reserved. // #import "ViewController.h" #import "FastCoder.h" @interface DataModel1 : NSObject @property (nonatomic,strong)NSArray *array; @property (nonatomic,strong)NSDictionary *dic; @property (nonatomic,copy)NSString *str; @property (nonatomic,assign)NSInteger age; //@property (nonatomic,strong)DataModel *model; @end @implementation DataModel1 @end @interface DataModel : NSObject @property (nonatomic,strong)NSArray *array; @property (nonatomic,strong)NSDictionary *dic; @property (nonatomic,copy)NSString *str; @property (nonatomic,assign)NSInteger age; @property (nonatomic,strong)DataModel1 *model; @end @implementation DataModel @end @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; DataModel *model00 = [[DataModel alloc]init]; model00.array = @[@"haha",@"1231212"]; model00.dic = @{@"111111111111--1-11--1-":@"1111"}; model00.str = @"11111"; model00.age = 123312132312; DataModel *model01 = [[DataModel alloc]init]; model01.array = @[@"haha",@"1231212"]; model01.dic = @{@"3213":@"1111"}; model01.str = @"11111"; model01.age = 123312132312; DataModel *model = [[DataModel alloc]init]; model.array = @[model00,model01]; model.dic = @{@"3213":@"1111"}; model.str = @"11111"; model.age = 123312132312; DataModel1 *model1 = [[DataModel1 alloc]init]; // model1.str = @"1121211"; model1.array = @[@"1111",@"11111"]; model.model = model1; NSData *data = [FastCoder dataWithRootObject:model]; DataModel *MODEL =[FastCoder objectWithData:data]; DataModel *model112 = MODEL.array[0]; NSLog(@"%@",model112.dic); NSLog(@"%@",MODEL.dic); NSLog(@"%@",MODEL.str); NSLog(@"%ld",MODEL.age); NSLog(@"%@",model.model.array); NSLog(@"%@",MODEL.model.str); if (MODEL.model.str == nil) { NSLog(@"对"); }else { NSLog(@"晓不得"); } NSLog(@"%@",data); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
由于测试所以没有写储存到本地,但是把模型转化为了NSData类型了,几种储存方式都可以的
![](http://images2015.cnblogs.com/blog/706432/201603/706432-20160304151818299-903683984.png)
注意:
![](http://images2015.cnblogs.com/blog/706432/201603/706432-20160304152008377-988958201.jpg)
相关文章推荐
- Mac finder 显示隐藏文件
- js实现继承
- ESXi安装到U盘
- 二进制流文流输出成zip
- Android中margin和padding的区别
- android广告植入
- RT-Thread下的串口驱动程序分析
- Spring 4.2.4.RELEASE MVC 学习笔记 - 8 - fasterxml jackson(咋个办呢 zgbn)
- 添加RichEdit控件导致MFC对话框程序无法执行的解决方法
- 安卓多线程编程系列2:异步任务的使用之使用异步任务带有进度的横向滚动条下载网络图片
- Zoho CEO:云计算泡沫巨大 Salesforce只是新的Siebel
- php字符串的比较
- Oracle 表空间记录
- Web开发中的Listener
- iOS给键盘添加一个简单的输入框
- 经典web系统学习,只有用户-角色,没有权限项
- 内核态文件操作
- 数据结构之“Ordered List and Sorted List”(三)
- try...catch的简单使用
- 如何从DataTable 中取得你要的数组