我有这个代码要求在
Swift 1.2中工作的写权限,升级到Swift 2.0后我得到一个奇怪的错误:
…’_’不能转换为’HKWorkoutType’
…’_’不能转换为’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?