2012-10-08 42 views
0

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

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(@"%@",[email protected]"success": @"failure"); 

失败和返回nil在还原时与:

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

的palineArray是一个NSMutableArray与值,系列化当如由先前的NSLog。 它可能是什么?它不符合NSMutableArray编码或什么?

感谢, 法布里奇奥

回答

0

只需将书的例子我从新增的外来应用程序缓存目录中的例子。