如何在Key in info plist下保存NSString?

时间:2016-06-18 08:55:33

标签: objective-c swift nsstring save info.plist

我想在info plist中的背景图像键下保存NSString。我怎样才能做到这一点 。有什么帮助吗?

我不知道如何在info.plist中读/写数据。任何人都可以告诉我该怎么做?

2 个答案:

答案 0 :(得分:1)

按照以下步骤操作:

右键点击您应用的 info.plist>打开>源代码

答案 1 :(得分:0)

更新或插入数据。 NSError *错误;     NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); // 1     NSString * documentsDirectory = [paths objectAtIndex:0]; // 2     NSString * path = [documentsDirectory stringByAppendingPathComponent:@“Mysoot.plist”]; // 3

NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager fileExistsAtPath: path]) //4
{
    NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Myspot" ofType:@"plist"]; //5

    [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile: path];

[data removeObjectForKey:@“BackgroundImage”];     [data setObject:imageName forKey:@“BackgroundImage”];

[data writeToFile: path atomically:YES];