swift 2.0 healthkit requestAuthorizationToShareTypes - 没有更多上下文的表达式类型不明确

Gut*_*ty1 0 healthkit swift2

在从swift 1.2转换为2.0之后,我收到以下错误:当我请求授权时,表达式的类型没有更多上下文,如下所示:

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

有任何想法吗?

Gut*_*ty1 9

我终于修复了问题,并且不确定它与错误消息本身有什么关系.

1)healthKitTypesToRead和write:从Set([])中删除[]

2)创建了一个新的完成重复

3)按照以下方式更改呼叫

例:

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)
Run Code Online (Sandbox Code Playgroud)

现在代码编译正确