NSKeyedArchiver archiveRootObject keeps returning NO

我的未来我决定 提交于 2019-12-01 08:32:14

You create a directory with the path fullPath and then you try to write the file at the same path. Overwriting a directory with a file like this is not possible. Use your cacheDirectory string to create your directory.

NSString *cacheDirectory is not a mutable string and after you init it, you attempt to modify it so you are writing to the top-level directory.

For a quick fix, try:

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,   NSUserDomainMask, YES);
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;
NSString *documentsResourcesPath = [documentPath  stringByAppendingPathComponent:@"MyAppCache"];

NSString *fullPath = [documentsResourcesPath stringByAppendingPathComponent:@"archive.data"];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!