• 归档


    1、将要归档的对象遵守协议@interface Account : NSObject<NSCoding>

    2、在m方法中实现2个方法

    //从文件中解析对象的时候调用
    - (id)initWithCoder:(NSCoder *)decoder
    {
        self = [super init];
        
        if (self) {
            self.access_token = [decoder decodeObjectForKey:@"access_token"];
            self.expires_in   = [decoder decodeInt64ForKey:@"expires_in"];//这用int64是因为属性为longlong类型
            self.remind_in = [decoder decodeInt64ForKey:@"remind_in"];
            self.uid = [decoder decodeInt64ForKey:@"uid"];
        }
        
        return self;
    }
    
    //将对象写入文件时调用
    - (void)encodeWithCoder:(NSCoder *)aCoder
    {
        [aCoder encodeObject:self.access_token forKey:@"access_token"];
        
        [aCoder encodeInt64:self.expires_in forKey:@"expires_in"];
        
        [aCoder encodeInt64:self.remind_in forKey:@"remind_in"];
        
        [aCoder encodeInt64:self.uid forKey:@"uid"];
        
        
    }

    第三步:归档

              Account *account = [Account accountWithDict:responseObject];
                
                //储存模型数据
                
                NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
                
                NSString *file = [doc stringByAppendingPathComponent:@"account.data"];
                
                [NSKeyedArchiver archiveRootObject:account toFile:file];

     4、解归档

     [NSKeyedUnarchiver unarchiveObjectWithFile:file];
     
  • 相关阅读:
    Kafka Streams演示程序
    大全Kafka Streams
    简介Kafka Streams
    初识Kafka
    面试常考各类排序算法总结.(c#)
    php程序员的成长之路
    web前端研发工程师编程能力成长之路
    CentOS 6.6编译安装Nginx1.6.2+MySQL5.6.21+PHP5.6.3
    【转】OkHttp使用进阶 译自OkHttp Github官方教程
    排序算法一:桶排序
  • 原文地址:https://www.cnblogs.com/huoxingdeguoguo/p/4721579.html
Copyright © 2020-2023  润新知