我的pNameDict为:
var pNameDict:[String: AnyObject] = [:]
此dict填充了plist文件中的数据,随后使用用户输入进行了更新。
当我尝试写回数据时,它不起作用。我确实看到pNameDict正在更新,但是写入失败。
func saveNames() {
var pListURL: URL?
var pListData: NSData?
do {
pListURL = Bundle.main.url(forResource: "Names", withExtension: "plist", subdirectory: "")
pListData = try PropertyListSerialization.data(fromPropertyList: pNameDict, format: .binary, options: 0) as NSData
pListData?.write(to: pListURL!, atomically: false)
} catch {
print("Could not write data to plist")
}
}