Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这个错误I';我到这里了?(iOS、Xcode、Healthkit)_Ios_Swift_Xcode_Healthkit - Fatal编程技术网

这个错误I';我到这里了?(iOS、Xcode、Healthkit)

这个错误I';我到这里了?(iOS、Xcode、Healthkit),ios,swift,xcode,healthkit,Ios,Swift,Xcode,Healthkit,这就是代码,除了定义HKHealthStore的init函数之外,没有其他的了。我得到的错误是在请求授权时 func reuqestConnection(){ var permReq: Set? = [HKObjectType.quantityType(forIdentifier: .heartRateVariabilitySDNN), HKObjectType.quantityType(forIdentifier: .restingHea

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

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
无法将“Set”类型的值转换为预期的参数类型“Set”
我不确定这意味着什么,因为我以前没有得到这个错误。我应该在这里干什么?

试试这个。 目前我对
HKObjectType.quantityType
使用了强制展开。你需要处理这件事

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

您正在用一个类型(Set?)的项填充数组,而期望的是另一个类型(Set)。哦,好吧,我错过了!。谢谢
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.
            }
        }
    }
}