Swift: 正在读取 plist 文件

Swift: reading plist file

我正在 swift 中为 objective-c 中的现有应用创建更新。我在 obj c 旧版本中使用 plist 文件来存储数据,现在我将用户数据保存在 CoreData 中,所以在更新后第一次启动时,我读取 plist 文件并设置一个字典,其中包含用户在 plist 文件中保存的值。 但问题是,保存的值不在字典中(只有我自己直接在 Xcode 的 plist 文件中设置的值在字典中)。

阅读Data.plist代码:

if let path = Bundle.main.path(forResource: "Data", ofType: "plist"), var tempDict = NSDictionary(contentsOfFile: path) as? [String: String] {
      print("tempDict = \(tempDict)")
}

打印结果:

tempDict = ["key1": "", "key2": ""]

但是 plist 文件中有值(文件已找到,键在字典中但不是值)。探索应用程序的容器数据和 Data.plist,值是存在的。

But PROBLEM is, the values saved aren't in the dictionnary (only values that I set myself directly in the plist file in Xcode are in the dictionnary

这意味着您需要更改主包,当然这是不允许的,因为您必须将文件复制到文档并对其进行任何更改,然后读取您写入的最新值,您可能正在探索复制文件的内容,而不是主包中存在的原始文件