作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有以下代码:
NSString *errorStr = nil;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dict
format:NSPropertyListBinaryFormat_v1_0
errorDescription:&errorStr];
if (errorStr) {
// Darn.
NSLog(@"saving dictionary error %@", errorStr);
} else {
// [plistData writeToFile:file atomically:YES];
// (ankit): Changing this to NO for speed.
success = [plistData writeToFile:file atomically:NO];
}
然而,对于以下字典,这将返回 NO:
{
entries = (
{
author = "Jada Wong";
cellIdentifier = default;
date = "2012-10-15 02:22:41 +0000";
domain = Readability;
feedUrl = "readability://feed";
imagesAreOnPulsesubscriber = 0;
order = 0;
summary = "";
templateUrl = "default_template.html";
title = "We\U2019re Going To Try Out Dolce & Gabbana\U2019s Beauty Look This Weekend";
url = "http://www.styleite.com/media/styledish-10122012/";
}
);
}
但它适用于以下字典:
{
entries = (
{
author = "Colleen Taylor";
cellIdentifier = default;
date = "2012-10-15 01:00:05 +0000";
domain = TechCrunch;
domainUrl = "http://techcrunch.com";
feedUrl = "http:/asdasdm/TechCrunch";
images = (
"http://asdshot-2012-10-14-at-5-20-43-pm.png"
);
imagesAreOnPulsesubscriber = 1;
lastUpdated = 1350263095;
order = 0;
shortLink = "http://bete.me/s/ej2Tg";
summary = "Bonobos, the men's clothing company, has gained lots of ground since it was founded in 2007 for its presence on the web as a mostly pure e-commerce p...";
templateUrl = "default_template.html";
title = "Inside Bonobos\U2019 New Palo Alto Digs, Where The Startup Known For E-Commerce Is Investing In Bricks & Mortar";
url = "http://techcrunch.com/2012/10/14/bonobos-palo-alto-mike-hart/";
}
);
}
知道为什么吗?它适用于不同的字典我写入的文件路径是:
/var/mobile/Applications/4B60A704-BE00-4160-BFB4-AD89187FADD1/Library/Caches/StoryCache/readability: feed
我得到的错误是:
"The operation couldn\u2019t be completed. (Cocoa error 512.)" UserInfo=0xb41580 {NSFilePath=/var/mobile/Applications/4B60A704-BE00-4160-BFB4-AD89187FADD1/Library/Caches/StoryCache/readability: feed, NSUnderlyingError=0xbb8930 "The operation couldn\u2019t be completed. Is a directory"}
最佳答案
使用 writeToFile:options:error:
而不是 writeToFile:atomically:
以便记录错误代码。
NSError *error;
success = [plistData writeToFile:file options:0 error:&error];
if (!success) {
NSLog(@"writeToFile failed with error %@", error);
}
根据您粘贴到问题中的错误,我猜您已经有一个名为 /var/mobile/Applications/4B60A704-BE00-4160-BFB4-AD89187FADD1/Library/Caches/StoryCache/readability: feed 的目录
。您不能用文件覆盖目录。您需要先重命名或删除该目录。您可以使用 -[NSFileManager removeItemAtPath:error:]
递归删除目录及其所有内容。
关于iphone - writeToFile 原子地返回 NO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12888445/
我是一名优秀的程序员,十分优秀!