我已经升级到了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)处。
有什么想法吗?