无法将时间'Int'的值转换为Swift 2中的预期参数类型'NSPropertyListReadOptions'

AJ1*_*152 2 iphone ios xcode7 swift2

我正在将现有代码升级到Swift 2,我需要一些帮助来保存Plist文件

这段代码在Xcode 6.3中工作,但现在使用Xcode 7和Swift 2,它显示了这个错误:

无法将时间'Int'的值转换为预期的参数类型'NSPropertyListReadOptions'(又名'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)
}
Run Code Online (Sandbox Code Playgroud)

请帮忙!

Pet*_*sey 7

我认为您不需要将options参数转换为Int,它应该采用NSPropertyListMutabilityOptions类型的值:

var notesArray = (try! NSPropertyListSerialization.propertyListWithData(data, options:NSPropertyListMutabilityOptions.MutableContainersAndLeaves, format: nil)) as! NSMutableArray
Run Code Online (Sandbox Code Playgroud)