试图使用下面的代码块,但不知道如何让选项位在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.
原文链接:https://www.f2er.com/swift/319173.html对于Int.
NSPropertyListMutabilityOptions是一个RawOptionSetType,其中Uint作为底层
原始类型.
因此,您必须将选项转换为Int with
appStats = NSPropertyListSerialization.propertyListWithData(appStatsData,options:Int(NSPropertyListMutabilityOptions.MutableContainersAndLeaves.rawValue),error: &error)