如何在 info plist 的 Key 下保存 NSString?
How to save NSString under Key in info plist?
我想将 NSString 保存在信息 plist 中的背景图像键下。我怎样才能做到这一点 。有帮助吗?
我不知道如何 read/write info.plist 中的数据。谁能告诉我该怎么做?
按照以下步骤操作:
右键单击您应用的 info.plist > 打开为 > 源代码
更新或插入数据。
NSError *错误;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [路径 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];
[数据 removeObjectForKey:@"BackgroundImage"];
[数据 setObject:imageName forKey:@"BackgroundImage"];
[data writeToFile: path atomically:YES];
我想将 NSString 保存在信息 plist 中的背景图像键下。我怎样才能做到这一点 。有帮助吗?
我不知道如何 read/write info.plist 中的数据。谁能告诉我该怎么做?
按照以下步骤操作:
右键单击您应用的 info.plist > 打开为 > 源代码
更新或插入数据。 NSError *错误; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1 NSString *documentsDirectory = [路径 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];
[数据 removeObjectForKey:@"BackgroundImage"]; [数据 setObject:imageName forKey:@"BackgroundImage"];
[data writeToFile: path atomically:YES];