从swift 1.2迁移后,swift2中的healthKit错误

Gut*_*ty1 4 ios swift healthkit swift2

我有这个代码要求Swift 1.2在升级到Swift 2.0我之后工作的写权限我得到一个奇怪的错误: ... '_' is not convertible to 'HKWorkoutType'

出现错误的代码行:

let healthKitTypesToWrite = Set(arrayLiteral:[
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned),
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning),
        HKQuantityType.workoutType()
        ])
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Jul*_*ról 5

添加!前两项:

let healthKitTypesToWrite = Set(arrayLiteral:
[
    HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)!, 
    HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)!, 
    HKQuantityType.workoutType() 
])
Run Code Online (Sandbox Code Playgroud)

这是必需的,因为quantityTypeForIdentifier退货HKQuantityType?