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

标签 ios iphone swift2 xcode7

我正在将我现有的代码升级到 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/

相关文章:

iphone - 如何为 NavigationController 使用 push Storyboard Segue

iphone - 如何找到调整 View 大小的位置/原因?

iphone - 为什么不使用 self 。类内调用

swift - 注释支持符合协议(protocol)的 Swift 函数声明?

ios - 为什么 UITextField 的文本属性在 Swift 2 中更改为可选?

iOS 11.2.1 Xcode 9.2 BoringSSL SSL_ERROR_ZERO_RETURN(6)

ios - 使用 UIPanGestureRecognizer 的可拖动 View 中的 Action 元素导致 View 移动

ios - 切换 ViewController 时的 UISwitch/UISlider 值

快速更改通知正文

ios - NSError localizedDescription 总是返回英文错误信息