0
这里是我的代码:为什么我不从NSKeyedUnarchiver获取数组?
NSString * path = kCachePath(kCacheFileName);
NSMutableArray * arry = [[NSMutableArray alloc]init];
arry = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
// NSData * data = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
// NSError *error = nil;
// arry = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &error];
if (arry) {
[arry addObject:playModel];
NSData * data = [NSKeyedArchiver archivedDataWithRootObject:arry];
[NSKeyedArchiver archiveRootObject:data toFile:path];
return YES;
} else {
NSMutableArray * ary = [NSMutableArray array];
[ary addObject:playModel];
NSData * data = [NSKeyedArchiver archivedDataWithRootObject:ary];
[NSKeyedArchiver archiveRootObject:data toFile:path];
}
我已经成功归档的阵列的文件,但是当我想解开的数据文件,我得到了一个NSMutableData', But I want an
的NSMutableArray . and I have tried the
NSJSONSerialization to conver the
NSData的to
的NSMutableArray and I got a
nil`。任何人都知道哪里出了问题?
这里是我cachePath:
#define kCacheFileName @"fakeLiveHistory.data"
#define kCachePath(kCacheFileName) ([NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:kCacheFileName])