2

我正在尝试读取 HKWorkout 的路线数据,但我无法读取,因为当我尝试HKWorkoutRouteQuery使用检索到的样本实例化 an 时,我的编辑器中出现错误提示“参数传递给不带参数的调用”。

在此处输入图像描述

根据Apple 的文档,我的代码如下所示:

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 使用示例进行实例化。

任何帮助将非常感激。非常感谢。

4

1 回答 1

8

Apple 通过 Bug Reporter 回复了我。问题是我忽略了导入 CoreLocation。您可以通过将以下行添加到文件顶部来修复此错误。

import CoreLocation

顺便说一句,我认为这是编写描述性错误重要性的一个很好的例子。如果错误提到了有关导致完成的内容需要CoreLocation,我将能够自己解决这个问题。

于 2018-06-28T19:10:34.677 回答