【问题标题】:What is exactly this error I'm getting here? (iOS, Xcode, Healthkit)我在这里遇到的这个错误到底是什么? (iOS、Xcode、Healthkit)
【发布时间】:2020-12-29 15:58:03
【问题描述】:
func reuqestConnection(){
    var permReq: Set? = [HKObjectType.quantityType(forIdentifier: .heartRateVariabilitySDNN),
                        HKObjectType.quantityType(forIdentifier: .restingHeartRate),
                        HKObjectType.quantityType(forIdentifier: .heartRate)]
    if let healthStore = healthStore{
        healthStore.requestAuthorization(toShare: nil, read: permReq){ (success, error) in
            if(!success){
                //redirect to error view to try again.
            }
        }
    }
}//func ends

这就是代码,除了定义 HKHealthStore 的 init 函数之外没有别的了。我得到的错误是在请求授权时

Cannot convert value of type 'Set<HKQuantityType?>?' to expected argument type 'Set<HKObjectType>?'

我不确定这意味着什么,因为我之前没有收到此错误。我应该在这里做什么?

【问题讨论】:

  • 您正在用一种类型的项目 (Set?) 填充数组,而预期的项目是另一个 (Set)。

标签: ios swift xcode healthkit


【解决方案1】:

试试这个。 目前我对HKObjectType.quantityType 使用了强制解包。你需要处理这个。

func reuqestConnection(){
    var permReq: Set = [HKObjectType.quantityType(forIdentifier: .heartRateVariabilitySDNN)!,
                        HKObjectType.quantityType(forIdentifier: .restingHeartRate)!,
                        HKObjectType.quantityType(forIdentifier: .heartRate)!]
    if let healthStore = healthStore{
        healthStore.requestAuthorization(toShare: nil, read: permReq ){ (success, error) in
            if(!success){
                //redirect to error view to try again.
            }
        }
    }
}

【讨论】:

  • 哦,好吧,我错过了!。谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-08-03
  • 2020-12-23
  • 1970-01-01
  • 2019-11-02
  • 1970-01-01
  • 2019-10-30
相关资源
最近更新 更多