我正在将我现有的代码升级到 Swift 2,我需要一些关于保存 Plist 文件的帮助
此代码在 Xcode 6.3 中工作,但现在在 Xcode 7 和 Swift 2 中显示此错误:
Cannot convert value of time 'Int' to expected argument type 'NSPropertyListReadOptions' (aka 'NSPropertyListMutabilityOptions')
var resultValue = "Value goes here"
@IBAction func saveNote(sender: AnyObject) {
// Save note to plist
var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var pathForThePlistFile = appDelegate.plistPathInDocument
// Extract the content of the file as NSData
var data:NSData = NSFileManager.defaultManager().contentsAtPath(pathForThePlistFile)!
// Convert the NSData to mutable array
var notesArray = (try! NSPropertyListSerialization.propertyListWithData(data, options: Int(NSPropertyListMutabilityOptions.MutableContainersAndLeaves.rawValue), format: nil)) as! NSMutableArray
//
notesArray.addObject(resultValue)
// Save to plist
notesArray.writeToFile(pathForThePlistFile, atomically: true)
}
请帮忙!
最佳答案
我认为您不需要将选项参数转换为 Int,它应该采用 NSPropertyListMutabilityOptions 类型的值:
var notesArray = (try! NSPropertyListSerialization.propertyListWithData(data, options:NSPropertyListMutabilityOptions.MutableContainersAndLeaves, format: nil)) as! NSMutableArray
关于ios - 无法将时间 'Int' 的值转换为 Swift 2 中的预期参数类型 'NSPropertyListReadOptions',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32405932/