Gutty1
Gutty1

Reputation: 535

healthKit error in swift2 after migration from swift 1.2

I had this code asking for write permissions working in Swift 1.2 and after upgrading to Swift 2.0 I getting a strange error: ... '_' is not convertible to 'HKWorkoutType'

code line where error appear:

let healthKitTypesToWrite = Set(arrayLiteral:[
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned),
        HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning),
        HKQuantityType.workoutType()
        ])

any ideas?

Upvotes: 4

Views: 249

Answers (1)

Julian
Julian

Reputation: 9337

Add ! for first two items:

let healthKitTypesToWrite = Set(arrayLiteral:
[
    HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierActiveEnergyBurned)!, 
    HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)!, 
    HKQuantityType.workoutType() 
])

This is required because quantityTypeForIdentifier returns HKQuantityType?

Upvotes: 5

Related Questions