我花了幾個小時試圖弄清楚這一點,但我已經用盡了想法。NSKeyedArchiver archiveRootObject不斷返回否
所有我想要做的是歸檔的對象,但在返回NO
archiveRootObject
保持方法,這裏是我的代碼:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = [paths objectAtIndex:0];
cacheDirectory = [cacheDirectory stringByAppendingPathComponent:@"MyAppCache"];
NSString *fullPath = [cacheDirectory stringByAppendingPathComponent:@"archive.data"];
if(![[NSFileManager defaultManager] fileExistsAtPath:fullPath]){
[[NSFileManager defaultManager] createDirectoryAtPath:fullPath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSArray *array = [NSArray arrayWithObjects:@"hello", @"world", nil];
NSLog(@"Full Path: %@", fullPath);
BOOL res = [NSKeyedArchiver archiveRootObject:array toFile:fullPath];
if(res){
NSLog(@"YES");
}else{
NSLog(@"NO");
}
每次時間我運行此,它打印NO
。
任何幫助,將不勝感激!
差不多拉了我的頭髮。謝謝你斯文! – Khon