编辑 iOS 中的现有 plist
Edit an existing plist in iOS
早上好,
我正在创建我的第一个 iphone 应用程序,请耐心等待。
我已经创建了一个 plist 并附上了一张图片,所以你可以看到我是如何设置它的。
我正在尝试在客户下添加另一个项目,其中包含 3 个键值对。
这是我目前拥有的,但我不明白如何编辑我保存的 plist。
NSString *plistCatPath = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
NSDictionary *clientDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistCatPath];
NSMutableArray *arrayTempClients = [[NSMutableArray alloc] initWithObjects:clientDictionary[@"Clients"], nil];
NSMutableArray *array1 = [[NSMutableArray alloc] initWithArray:arrayTempClients[0]];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
dict[@"Description"] = @"testAccount";
dict[@"Username"] = @"customUsername";
dict[@"Password"] = @"customPassword";
[array1 addObject:dict];
任何帮助将不胜感激!
您不能对应用程序进行任何更改,其中包括文件。
如果您需要可以编辑的 plist 版本,那么在首次启动时将 plist 文件复制到应用程序的文档目录中。然后你可以把它读入一个NSMutableDictionary
,添加新数据并保存回来。
早上好,
我正在创建我的第一个 iphone 应用程序,请耐心等待。 我已经创建了一个 plist 并附上了一张图片,所以你可以看到我是如何设置它的。
我正在尝试在客户下添加另一个项目,其中包含 3 个键值对。
这是我目前拥有的,但我不明白如何编辑我保存的 plist。
NSString *plistCatPath = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
NSDictionary *clientDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistCatPath];
NSMutableArray *arrayTempClients = [[NSMutableArray alloc] initWithObjects:clientDictionary[@"Clients"], nil];
NSMutableArray *array1 = [[NSMutableArray alloc] initWithArray:arrayTempClients[0]];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
dict[@"Description"] = @"testAccount";
dict[@"Username"] = @"customUsername";
dict[@"Password"] = @"customPassword";
[array1 addObject:dict];
任何帮助将不胜感激!
您不能对应用程序进行任何更改,其中包括文件。
如果您需要可以编辑的 plist 版本,那么在首次启动时将 plist 文件复制到应用程序的文档目录中。然后你可以把它读入一个NSMutableDictionary
,添加新数据并保存回来。