Gutty1
Gutty1

Reputation: 535

swift 2.0 healthkit requestAuthorizationToShareTypes - Type of expression is ambiguous without more context

after converting from swift 1.2 to 2.0 I get the following error: Type of expression is ambiguous without more context when I request for authorisation as follow:

healthKitStore.requestAuthorizationToShareTypes(writeTypes: healthKitTypesToWrite, readTypes: healthKitTypesToRead,completion:  { success, error in
        if success {
            print("SUCCESS")
        } else {
            print(error.description)
        }
        })

any ideas?

Upvotes: 0

Views: 1881

Answers (1)

Gutty1
Gutty1

Reputation: 535

I finally fixed the problem, and not sure it has anything to do with the error message itself.

1) healthKitTypesToRead and write: removed the [ ] from Set ( [ ] )

2) created a new completion duple

3) changed the call as follow bellow

example:

let healthKitTypesToRead = Set(
        arrayLiteral: HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierDateOfBirth)!,
        HKObjectType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex)!,
        HKObjectType.workoutType()
        )

let newCompletion: ((Bool, NSError?) -> Void) = {
        (success, error) -> Void in

        if !success {
            print("You didn't allow HealthKit to access these write data types.\nThe error was:\n \(error!.description).")

            return
        }
    }


healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead, completion: newCompletion)

now the code compiles properly

Upvotes: 9

Related Questions