我有这段代码要求在Swift 1.2
中工作的写权限,并且在升级到Swift 2.0
后,我得到一个奇怪的错误:... '_' is not convertible to 'HKWorkoutType'
出现错误的代码行:
let healthKitTypesToWrite = Set(arrayLiteral:[
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned),
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning),
HKQuantityType.workoutType()
])
有任何想法吗?
最佳答案
为前两个项目添加!
:
let healthKitTypesToWrite = Set(arrayLiteral:
[
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)!,
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)!,
HKQuantityType.workoutType()
])
这是必需的,因为
quantityTypeForIdentifier
返回HKQuantityType?