【问题标题】:NSMutableArray caching failureNSMutableArray 缓存失败
【发布时间】:2012-10-08 17:32:23
【问题描述】:

我想缓存一些 https 请求的结果以加速用户界面,所以我想在 applicationWillResignActive: 中缓存数据并在 didFinishLaunchingWithOptions 中恢复它。 为此,我使用以下代码 sn-p: NSArray *paths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

NSString* cachesDirectory=[paths objectAtIndex:0];

NSString* archivePath=[cachesDirectory stringByAppendingPathComponent:@"AppCache/Paline.archive"];

NSLog(@"archivePath=%@ paline=%@", archivePath, detailViewController.palineArray);

BOOL success=[NSKeyedArchiver archiveRootObject:detailViewController.palineArray toFile:archivePath];

NSLog(@"%@",success?@"success": @"failure");

失败并在恢复时返回 nil:

 NSMutableArray* cachedItems=[NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
 NSLog(@"archivePath=%@ cache=%@", archivePath, cachedItems);

palineArray 是一个带有值的 NSMutableArray,当序列化时,如前面的 NSLog 所示。 会是什么呢?是不符合 NSMutableArray 编码还是什么?

谢谢, 法布里奇奥

【问题讨论】:

    标签: xcode encoding nsmutablearray


    【解决方案1】:

    只是我从添加一个无关的 AppCache 目录中获取的示例的书的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 2020-01-07
      • 2017-10-01
      • 1970-01-01
      • 2013-12-25
      • 2019-07-11
      相关资源
      最近更新 更多