这个plist在模拟器上正常工作...读取和写入plist数据没有问题!正确地工作也删除数据。它不会崩溃! 如果改为在设备上启动应用程序,请不要读取任何数据! 我使用的是Swift 3版本8.3.2。
有什么想法吗?
提前感谢!
阅读plist
let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true) as NSArray
let documentsDirectory:AnyObject = paths[0] as AnyObject
let path = documentsDirectory.appending("orari_marcate.plist")
let fileManager = FileManager.default
let fileExists:Bool = fileManager.fileExists(atPath: path)
let lista_marcate : NSMutableDictionary = NSMutableDictionary()
var marcate2 = NSMutableArray()
if fileExists == false {
marcate2 = NSMutableArray()
} else {
marcate2 = NSMutableArray(contentsOfFile: path)!
}
写plist
lista_marcate.setValue(risultato_Ora.text, forKey: "fine_Ora")
lista_marcate.setValue(risultato_Min.text, forKey: "fine_Min")
marcate2.add(lista_marcate)
marcate2.write(toFile: path, atomically: true)