gpt4 book ai didi

ios - 无法将类型 '[HKQuantityType?]' 的值转换为指定类型 'Set'

转载 作者:行者123 更新时间:2023-11-28 13:05:39 24 4
gpt4 key购买 nike

更新到 Swift 2 时出现此错误

Cannot convert value of type '[HKQuantityType?]' to specified type 'Set'

private let stepsCountIdentifier = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)


func authorizeHealthKit(completion: ((success: Bool, error: NSError?) -> Void)) {
let healthKitTypesToRead: Set = [stepsCountIdentifier]

if !HKHealthStore.isHealthDataAvailable() {
completion(success: false, error: NSError(domain: "steps", code: -1, userInfo: nil))
return
}

healthKitStore.requestAuthorizationToShareTypes(Set(), readTypes: healthKitTypesToRead) { (success, error) -> Void in
completion(success: success, error: error)
}
}

最佳答案

在初始化 healthKitTypesToRead 集之前,您需要解包可选的 stepCountIdentifier

if let stepsCountIdentifierUnwrapped = stepsCountIdentifier {
let healthKitTypesToRead: Set = [stepsCountIdentifierUnwrapped]
}

关于ios - 无法将类型 '[HKQuantityType?]' 的值转换为指定类型 'Set',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32846639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com