'Copy Bundle resource' 中的 plist 文件是只读的吗?

Is plist file in 'Copy Bundle resource' Read-Only?

创建plist文件,成功读取数据

但是我无法写入文件。 (例如,将布尔值 NO 更改为 YES。 NSMutableDictionaty 的 writeToFile 不起作用)

文件路径如下。

NSString* path = [[NSBundle mainBundle] pathForResource:@"Setting" ofType:@"plist"];

我也是这样写值的

 [myDict setObject:[NSNumber numberWithBool:NO] forKey:@"isFirst"];
 [myDict writeToFile:path atomically:YES];

plist 文件是否 'Copy Bundle resource' 只读?

包总是只读的

'workaround'

将文件复制到应用程序的文档目录。在那里 R/W

pseudo-code 打开文件:

path = filePathInDocumentsFolder
file = read(path)
if(!file) {
    copy(plistFromBundle to path)
    file = read(path)
}