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