swift 2.0 healthkit requestAuthorizationToShareTypes - 表达式类型在没有更多上下文的情况下不明确
swift 2.0 healthkit requestAuthorizationToShareTypes - Type of expression is ambiguous without more context
从 swift 1.2 转换为 2.0 后,出现以下错误:
没有更多上下文,表达式类型不明确
当我请求授权时如下:
healthKitStore.requestAuthorizationToShareTypes(writeTypes: healthKitTypesToWrite, readTypes: healthKitTypesToRead,completion: { success, error in
if success {
print("SUCCESS")
} else {
print(error.description)
}
})
有什么想法吗?
我终于解决了这个问题,不确定它与错误消息本身有什么关系。
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)
现在代码可以正确编译
从 swift 1.2 转换为 2.0 后,出现以下错误: 没有更多上下文,表达式类型不明确 当我请求授权时如下:
healthKitStore.requestAuthorizationToShareTypes(writeTypes: healthKitTypesToWrite, readTypes: healthKitTypesToRead,completion: { success, error in
if success {
print("SUCCESS")
} else {
print(error.description)
}
})
有什么想法吗?
我终于解决了这个问题,不确定它与错误消息本身有什么关系。
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)
现在代码可以正确编译