gpt4 book ai didi

iphone - 将字符串类型的新键/值添加到 pList

转载 作者:行者123 更新时间:2023-11-28 23:12:39 25 4
gpt4 key购买 nike

我正在尝试以编程方式将新行添加到我在 iPhone 上的 pList 文件中。但我不知道怎么做。我想添加 key: someKey/type: string/someValue: string

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

NSMutableDictionary *plist = [[NSDictionary dictionaryWithContentsOfFile:path] mutableCopy];
NSMutableArray *newArray = [[[NSMutableArray alloc] init] autorelease];
newArray = [NSArray arrayWithObjects:@"someKey", @"someValue", nil];
[plist setObject:newArray forKey:@"someKey"];
[plist writeToFile:path atomically:YES];
[plist release];

最佳答案

您不能修改应用程序包中的文件,而这正是您上面的代码试图做的。

如果文件应该是可修改的,您需要先将它移动到文档文件夹中(比如,在第一次运行时),然后再读/写到那个文件夹。关于如何做到这一点有很多问题,例如:copying plist to document directory

关于iphone - 将字符串类型的新键/值添加到 pList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7738447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com