【问题标题】:How to save an array of dictionary to plist? [duplicate]如何将字典数组保存到plist? [复制]
【发布时间】:2013-02-23 09:00:56
【问题描述】:

Plist 只是不会保存自己...

我不明白我在这里做错了什么。请帮忙。

NSString *factorsFile = [[NSBundle mainBundle]pathForResource:@"factors" ofType:@"plist"];
NSMutableArray *factorsArray = [NSMutableArray arrayWithContentsOfFile:factorsFile];

NSMutableDictionary *dictFactor = [NSMutableDictionary dictionary];
[dictFactor setObject:self.nameField.text forKey:@"Factor"];
[dictFactor setObject:self.rankField.text forKey:@"Rank"];

NSLog(@"%@",dictFactor);

[factorsArray addObject:dictFactor];

NSLog(@"%@",factorsArray);

if([factorsArray writeToFile:factorsFile atomically:YES]){
    NSLog(@"lalal");
}

这段代码可以进入最后一个 if 循环,但 plist 保持不变...为什么?

【问题讨论】:

    标签: ios objective-c nsdictionary


    【解决方案1】:

    因为您无法在 app bundle 中写入/修改文件。

    但是,您可以对表达式 "ios plist write to bundle unchanged" 执行 Google 搜索,然后您可以查看前四个结果。它们都是相同/重复的 StackOverflow 问题:

    plist writing data inside dictionary

    write into plist file using NSDictionary object

    Not Able to write Boolean in plist file

    writeToFile fails on iphone but works on simulator

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-18
      • 2020-02-19
      • 2020-02-13
      • 1970-01-01
      • 2011-01-08
      • 2021-08-26
      • 1970-01-01
      相关资源
      最近更新 更多