从swift 1.2转换为2.0后,我收到以下错误: 如果没有更多的上下文,表达的类型是不明确的 当我申请授权时如下:
healthKitStore.requestAuthorizationToShareTypes(writeTypes: healthKitTypesToWrite, readTypes: healthKitTypesToRead,completion: { success, error in
if success {
print("SUCCESS")
} else {
print(error.description)
}
})
任何想法?
答案 0 :(得分:9)
我终于修复了问题,并且不确定它与错误消息本身有什么关系。
1)healthKitTypesToRead and 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)
现在代码正确编译