'Argument passed to call that takes no arguments' 实例化 HKWorkoutRouteQuery
'Argument passed to call that takes no arguments' instantiating HKWorkoutRouteQuery
我正在尝试读取 HKWorkout 的路线数据,但我不能,因为当我尝试用我的 HKWorkoutRouteQuery
实例化一个 HKWorkoutRouteQuery
检索样本。
根据 Apple's documentation,我的代码如下所示:
func getRouteData() -> [(Double)] {
// Return early if not a distance workout
guard self.shouldShowDistance else {
return []
}
let store = HKHealthStore()
let runningObjectQuery = HKQuery.predicateForObjects(from: self.workout)
let routeQuery = HKAnchoredObjectQuery(type: HKSeriesType.workoutRoute(), predicate: runningObjectQuery, anchor: nil, limit: HKObjectQueryNoLimit) { (query, samples, deletedObjects, anchor, error) in
guard error == nil else {
// Handle any errors here.
fatalError("query failed")
}
guard samples != nil else {
fatalError("No samples")
}
guard samples!.count > 0 else { fatalError("No samples") }
guard let route = samples?.first as? HKWorkoutRoute else {
fatalError("No samples")
}
// Create the route query.
let query = HKWorkoutRouteQuery(route: route) { (query, locationsOrNill, done, errorOrNil) in
// This block may be called multiple times.
if let error = errorOrNil {
// Handle any errors here.
return
}
guard let locations = locationsOrNil else {
fatalError("*** Invalid State: This can only fail if there was an error. ***")
}
// Do something with this batch of location data.
if done {
// The query returned all the location data associated with the route.
// Do something with the complete data set.
}
// You can stop the query by calling:
// store.stop(query)
}
store.execute(query)
}
store.execute(routeQuery)
return []
}
这对我来说毫无意义,因为 Apple 自己的文档要求使用示例实例化 HKWorkoutRouteQuery。
如有任何帮助,我们将不胜感激。非常感谢。
Apple 通过 Bug Reporter 回复了我。问题是我忽略了导入 CoreLocation。您可以通过将以下行添加到文件顶部来修复此错误。
import CoreLocation
顺便说一句,我认为这是一个很好的例子,说明了描述性错误的重要性。如果错误提到了需要 CoreLocation
完成的结果,我本来可以自己解决的。
我正在尝试读取 HKWorkout 的路线数据,但我不能,因为当我尝试用我的 HKWorkoutRouteQuery
实例化一个 HKWorkoutRouteQuery
检索样本。
根据 Apple's documentation,我的代码如下所示:
func getRouteData() -> [(Double)] {
// Return early if not a distance workout
guard self.shouldShowDistance else {
return []
}
let store = HKHealthStore()
let runningObjectQuery = HKQuery.predicateForObjects(from: self.workout)
let routeQuery = HKAnchoredObjectQuery(type: HKSeriesType.workoutRoute(), predicate: runningObjectQuery, anchor: nil, limit: HKObjectQueryNoLimit) { (query, samples, deletedObjects, anchor, error) in
guard error == nil else {
// Handle any errors here.
fatalError("query failed")
}
guard samples != nil else {
fatalError("No samples")
}
guard samples!.count > 0 else { fatalError("No samples") }
guard let route = samples?.first as? HKWorkoutRoute else {
fatalError("No samples")
}
// Create the route query.
let query = HKWorkoutRouteQuery(route: route) { (query, locationsOrNill, done, errorOrNil) in
// This block may be called multiple times.
if let error = errorOrNil {
// Handle any errors here.
return
}
guard let locations = locationsOrNil else {
fatalError("*** Invalid State: This can only fail if there was an error. ***")
}
// Do something with this batch of location data.
if done {
// The query returned all the location data associated with the route.
// Do something with the complete data set.
}
// You can stop the query by calling:
// store.stop(query)
}
store.execute(query)
}
store.execute(routeQuery)
return []
}
这对我来说毫无意义,因为 Apple 自己的文档要求使用示例实例化 HKWorkoutRouteQuery。
如有任何帮助,我们将不胜感激。非常感谢。
Apple 通过 Bug Reporter 回复了我。问题是我忽略了导入 CoreLocation。您可以通过将以下行添加到文件顶部来修复此错误。
import CoreLocation
顺便说一句,我认为这是一个很好的例子,说明了描述性错误的重要性。如果错误提到了需要 CoreLocation
完成的结果,我本来可以自己解决的。