【发布时间】:2015-09-24 14:39:37
【问题描述】:
我更新到 Swift 2 和 Xcode 7 并运行了迁移工具。然后我得到了很多错误。我坚持的一个是这个
func authorizeHealthKit(completion: ((success:Bool, error:NSError?) throws -> Void)?)
{
// 1. Set the types you want to read from HK Store
let healthKitTypesToRead = (array:[
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)
])
// 2. Set the types you want to write to HK Store
let healthKitTypesToWrite = (array:[
HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)
])
// 3. If the store is not available (for instance, iPad) return an error and don't go on.
if !HKHealthStore.isHealthDataAvailable()
{
var error = NSError.self
if( completion != nil )
{
completion(success:false, error:&error)
}
return;
}
// 4. Request HealthKit authorization
healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToWrite as Set<NSObject>, readTypes: healthKitTypesToRead as Set<NSObject>) { (success, error) -> Void in
if( completion != nil )
{
completion(success:success,error:error)
}
}
}
错误正在完成(success:false, error&error)
有什么想法吗?
【问题讨论】: