在设备上存储Plist的正确FilePath是什么。

我在教程中读到了这一点

将为计算机工作,想知道设备的文件位置。

// write xml representation of dictionary to a file
[dictionary writeToFile:@"/Users/henrik/Sites/foo.plist" atomically:NO];
.

我目前尝试写入我从

读取的文件路径
NSString *filepath = [[NSBundle mainBundle] 
                      pathForResource:@"UserAdded" ofType:@"plist"];
userAddedQuotes = [[NSMutableArray alloc] initWithContentsOfFile:filepath];
.

如下

[userAddedQuotes addObject:temp];
    [userAddedQuotes writeToFile:filepath atomically: NO];
.

数组在运行时更新,但不会保存到plist中。

有帮助吗?

解决方案

您无法写入应用程序包中的任何文件(包括您的资源目录)。如果要写文件,则应将其写入应用程序文档或库文件夹,具体取决于文件是什么。例如:

NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
.

将返回一系列路径,首先是您的文档目录。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top