更新到Swift 2时出现此错误
无法将'[HKQuantityType?]'类型的值转换为指定类型'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)
}
}
答案 0 :(得分:2)
在初始化stepCountIdentifier
集之前,您需要打开可选的healthKitTypesToRead
。
if let stepsCountIdentifierUnwrapped = stepsCountIdentifier {
let healthKitTypesToRead: Set = [stepsCountIdentifierUnwrapped]
}