How to write to plist successfully?

本小妞迷上赌 提交于 2019-11-28 14:41:58

I'm writing to file in such way:

NSString *errorDesc = nil;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *plistPath = [rootPath stringByAppendingString:TEMPLATES_PATH];
NSDictionary *dict = [NSDictionary dictionaryWithObject:templates forKey:@"templates"];
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dict format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
if (plistData)
{
    [plistData writeToFile:plistPath atomically:YES];
}else
{
    NSLog(@"[Error] Application Did Enter Background {saving file error}: %@", errorDesc);
    [errorDesc release];
}

Be sure to save file in app documents directory.

I don't believe you can write to a resource. Only files in the documents directory can be written to.

You can't write to files that are located in you Bundle. The app bundle is read only.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!