2015-09-04 30 views
2

我升级我的现有代码转换的时间价值“诠释”预期参数类型“NSPropertyListReadOptions”斯威夫特2,我需要一些帮助,plist文件中不能在斯威夫特2

该代码的保存在Xcode 6.3是工作,但现在的Xcode 7和斯威夫特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) 
} 

请帮助!

回答

7

我不认为你需要的选项参数转换为int,应采取型NSPropertyListMutabilityOptions值:

var notesArray = (try! NSPropertyListSerialization.propertyListWithData(data, options:NSPropertyListMutabilityOptions.MutableContainersAndLeaves, format: nil)) as! NSMutableArray 
+0

谢谢,这工作! – AJ152

2

您无法通过自己的苹果开发自己定义的选项有一些规则和已经告诉你只能使用2个选项属性。您的理解我正在衔接的NSropertyListSerialization的文档,请仔细阅读它,你就会明白该怎么做

要么你可以使用

NSPropertyListMutabilityOptions 

要么

NSPropertyListReadOptions 

或零

int将不会在这里支持