【问题标题】:swift 2.0 healthkit requestAuthorizationToShareTypes - Type of expression is ambiguous without more contextswift 2.0 healthkit requestAuthorizationToShareTypes - 表达式类型不明确,没有更多上下文
【发布时间】:2015-08-05 09:51:08
【问题描述】:

从 swift 1.2 转换为 2.0 后,我收到以下错误: 在没有更多上下文的情况下,表达式的类型是模棱两可的 当我请求如下授权时:

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

有什么想法吗?

【问题讨论】:

  • 我会修复 println() 并重试(println() 在 Swift 2.0 AFAK 中是非法的,应该是 print())。发布生成的错误字符串。如果您使用 StackOverflow 界面中的“代码”工具格式化代码会更有帮助。
  • 我已经更正了要打印的println,反正这个错误与那个无关,我正在更正我放的例子以避免误导信息

标签: swift2 healthkit


【解决方案1】:

我终于解决了这个问题,但不确定它与错误消息本身有什么关系。

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)

现在代码可以正确编译

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 2019-04-23
    • 1970-01-01
    相关资源
    最近更新 更多