zoukankan      html  css  js  c++  java
  • 将模型储存到本地-FastCoder

    //
    //  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类型了,几种储存方式都可以的

    注意:

  • 相关阅读:
    java并发:简单面试问题集锦
    Java:泛型
    Java:注解(元数据)
    Java:反射
    Java:静态代理 and 动态代理
    华为机试题——该警醒了,骚年
    java并发:线程同步机制之Lock
    java并发:中断一个正在运行的线程
    java中String类型变量的赋值问题
    java中的自增问题
  • 原文地址:https://www.cnblogs.com/hxwj/p/5242210.html
Copyright © 2011-2022 走看看