2
我無法跟蹤將NSDictionary
對象數組寫入文件的問題。NSArray writeFileToPath失敗
NSDictionary
對象中的每個鍵都是NSString
s,值也是如此。所以數組應該可寫入plist,因爲文檔狀態是必需的。總之,這裏是我的代碼:
BOOL success = [representations writeToFile:[self filePathForCacheWithCacheID:cacheID] atomically:YES];
//success is NO
文件路徑的方法是這樣的:
+ (NSString *)filePathForCacheWithCacheID:(NSString *)cacheID
{
NSURL *cachesDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];
return [[cachesDirectory URLByAppendingPathComponent:cacheID] absoluteString];
}
和cacheID是字符串 「對象」。在運行時,filePathForCacheWithCacheID:
方法返回像繩子:
file:///Users/MyName/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/3A57A7B3-A522-4DCC-819B-DC8DEEDCD041/Library/Caches/objects
可能是錯誤怎麼回事?
什麼是您要寫入的文件路徑?我的意思是,在運行時,你的'filePathForCacheWithCacheID:'方法返回什麼值? –
對於sim:file:///Users/MyName/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/3A57A7B3-A522-4DCC-819B-DC8DEEDCD041/Library/Caches/objects –