缓存

存储缓存:第三方应用只能把信息保存在应用程序的沙盒中,因为缓存数据不是用户产生,所以应该将其保存在NSCahcesDictionary中而不是NSDocumentsDirectory中。因为把缓存存储在缓存文件夹下的原因是iCloud(和iTunes)的备份不包括此目录。如果放在了Documents目录下创建的大缓存将备份到iCloud的有限空间中。
 *  序列化数据
 *  以keyValue形式对基本数据类型Encoding
 */
-(void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:_title forKey:@"title"];
    [aCoder encodeObject:_content forKey:@"content"];
    [aCoder encodeObject:_modelId forKey:@"modelId"];
}

/**
 *  反序列化数据
 *  以keyValue形式对基本数据类型Decoding,返回数据模型本身
 */
-(id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        NSLog(@"----> %s",__FUNCTION__);
        self.title = [aDecoder decodeObjectForKey:@"title"];
        self.content = [aDecoder decodeObjectForKey:@"content"];
        self.modelId = [aDecoder decodeObjectForKey:@"modelId"];
    }
    return self;
}


    for ( int i = 0;  i < 10; i++) {
        model= [[ZQModel alloc] init];
        model.title = [NSString stringWithFormat:@"title%d",i];
        model.content = [NSString stringWithFormat:@"content%d",i];
        model.modelId = [NSString stringWithFormat:@"modelId%d",i];
        [self.modelsArray addObject:model];
    }
    
    if ([NSKeyedArchiver archiveRootObject:self.modelsArray toFile:[[YCTools alloc] getCachePath:@"Appcache"]]) {
        NSLog(@"<<<<< success >>>>");
    }

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSString * path = [[YCTools alloc] getCachePath:@"Appcache"];
    cellArray  = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    [self.tableView reloadData];
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值