gpt4 book ai didi

objective-c - Mac OSX 如何添加 plist 来捆绑和修改 plist

转载 作者:搜寻专家 更新时间:2023-10-30 20:00:10 24 4
gpt4 key购买 nike

我有一个 plist,我将 plist 复制到我的 xcode 项目,但似乎文件不在包中:

NSDictionary *dict = [[NSBundle mainBundle] infoDictionary];
nslog (@"dict %@",dict);

但是文件 plist 文件没有显示。问题,我怎样才能以在包中看到的方式将文件添加到项目中?还有你们知道如何修改 plist 并保存更改吗?

非常感谢你的帮助

附言我正在使用 Xcode 5。

最佳答案

您可以在您的包中创建一个 plist 文件并将其内容修改为:

NSString *bundlePath = [[NSBundle mainBundle]bundlePath]; //Path of your bundle
NSString *path = [bundlePath stringByAppendingPathComponent:@"MyPlist.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];

NSMutableDictionary *data;

if ([fileManager fileExistsAtPath: path])
{
data = [[NSMutableDictionary alloc] initWithContentsOfFile: path]; // if file exist at path initialise your dictionary with its data
}
else
{
// If the file doesn’t exist, create an empty dictionary
data = [[NSMutableDictionary alloc] init];
}

//To insert the data into the plist
int value = 5;
[data setObject:[NSNumber numberWithInt:value] forKey:@"value"];
[data writeToFile: path atomically:YES];
[data release];

//To retrieve the data from the plist
NSMutableDictionary *savedData = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
int savedValue;
savedValue = [[savedData objectForKey:@"value"] intValue];
NSLog(@"%i",savedValue);

关于objective-c - Mac OSX 如何添加 plist 来捆绑和修改 plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19615248/

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