这个错误I';我到这里了?(iOS、Xcode、Healthkit)
这就是代码,除了定义HKHealthStore的init函数之外,没有其他的了。我得到的错误是在请求授权时这个错误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
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.
}
}
}
}