尝试使用下面的代码块,但不知道如何让选项位在 else 子句中工作,我不断收到“NSPropertyListMutabilityOptions”无法转换为“NSPropertyListReadOptions”的消息。但是 Read 选项没有我需要的 MutableContainersWithLeaves。
//if the file does not already exist
if(appStatsData != nil) {
appStats.setObject(NSNumber.numberWithInt(0), forKey:"RunCount")
appStats.setObject("No Courses Viewed", forKey:"LastCourseViewed")
}else {
appStats = NSPropertyListSerialization.propertyListWithData(appStatsData, options: NSPropertyListMutabilityOptions.MutableContainersAndLeaves, format: nil, error: &error)
}
最佳答案
options
参数的类型为 NSPropertyListReadOptions
,它是一个类型别名
用于Int
。NSPropertyListMutabilityOptions
是以 RawOptionSetType
作为底层的 Uint
原始类型。
因此,您必须将选项转换为 Int
appStats = NSPropertyListSerialization.propertyListWithData(appStatsData,
options:Int(NSPropertyListMutabilityOptions.MutableContainersAndLeaves.rawValue),
format: nil, error: &error)
关于swift - 快速使用 NSPropertyListSerialization.propertyListWithData,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25457766/