我无法追踪将NSDictionary
对象数组写入文件的问题。
NSDictionary
对象中的每个键都是NSString
s,值也是。因此,该数组应该可写入 plist,因为文档状态是必要的。无论如何,这是我的代码:
BOOL success = [representations writeToFile:[self filePathForCacheWithCacheID:cacheID] atomically:YES];
//success is NO
filePath 方法如下所示:
+ (NSString *)filePathForCacheWithCacheID:(NSString *)cacheID
{
NSURL *cachesDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];
return [[cachesDirectory URLByAppendingPathComponent:cacheID] absoluteString];
}
cacheID 是字符串“objects”。在运行时,该filePathForCacheWithCacheID:
方法返回一个字符串,如:
file:///Users/MyName/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/3A57A7B3-A522-4DCC-819B-DC8DEEDCD041/Library/Caches/objects
这里可能出了什么问题?