Kho*_*hon 3 nskeyedarchiver ios
我花了几个小时试图解决这个问题,但我已经没想完了.
我要做的就是归档一个对象,但该方法archiveRootObject一直在返回NO
这是我的代码:
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");
}
Run Code Online (Sandbox Code Playgroud)
每次我运行它,它都会打印出来NO.
任何帮助,将不胜感激!
| 归档时间: |
|
| 查看次数: |
5490 次 |
| 最近记录: |