代码之家  ›  专栏  ›  技术社区  ›  solarissf

在iOS中编辑现有plist

  •  0
  • solarissf  · 技术社区  · 10 年前

    早上好

    我正在创建我的第一个iphone应用程序,请耐心等待。 我已经创建了一个plist,并附上了一张图片,这样你就可以看到我是如何设置它的。

    我正在尝试在Clients下添加另一个Item,其中有3个keyvalue对。

    这是我目前所拥有的,但我不知道如何编辑我保存的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];
    

    enter image description here

    任何帮助都将不胜感激!

    1 回复  |  直到 10 年前
        1
  •  1
  •   zaph    10 年前

    您不能对应用程序进行任何更改,其中包括文件。

    如果您需要plist的一个版本,您可以编辑,然后在第一次启动时将plist文件复制到应用程序的Document目录中。然后你可以把它读成 NSMutableDictionary ,添加新数据并将其保存回。