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/"; } );}
但它适用于以下dict:
{ 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);}
UPDATE
根据您粘贴到问题中的错误,我猜您已经有一个名为/ var / mobile / Applications / 4B60A704-BE00-4160-BFB4-AD89187FADD1 / library / Caches / StoryCache / readability:Feed的目录.您无法使用文件覆盖目录.您需要先重命名或删除目录.您可以使用 – [NSfileManager removeItemAtPath:error:]以递归方式删除目录及其所有内容.
总结以上是内存溢出为你收集整理的iphone – writeToFile原子地返回NO全部内容,希望文章能够帮你解决iphone – writeToFile原子地返回NO所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)