无法将时间 'Int' 的值转换为 Swift 中预期的参数类型 'NSPropertyListReadOptions' 2
Cannot convert value of time 'Int' to expected argument type 'NSPropertyListReadOptions' in Swift 2
我正在将我现有的代码升级到 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
您不能通过自己的 apple 开发定义自己的选项有一些规则,并且已经告诉您只能使用 2 个选项 属性。为了您的理解,我正在链接 NSropertyListSerialization 的文档,请仔细阅读它,您将了解如何做到这一点
你可以使用
NSPropertyListMutabilityOptions
任一
NSPropertyListReadOptions
或无
这里不支持int
我正在将我现有的代码升级到 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
您不能通过自己的 apple 开发定义自己的选项有一些规则,并且已经告诉您只能使用 2 个选项 属性。为了您的理解,我正在链接 NSropertyListSerialization 的文档,请仔细阅读它,您将了解如何做到这一点
你可以使用
NSPropertyListMutabilityOptions
任一
NSPropertyListReadOptions
或无
这里不支持int