CMMotionActivityManager queryActivityStarting data not available outside closure
问题 I have this code to get historical motion activity from using CoreMotionActivity. func buildActivityArray() -> Array<Any> { let now = Date() let then = Date().addingTimeInterval(-3600) var motionManager: CMMotionActivityManager! motionManager = CMMotionActivityManager() var activityList: [Any] = [] motionManager.queryActivityStarting(from: then, to: now, to: .main) { motionActivities, error in if let error = error { print("error: \(error.localizedDescription)") return } motionActivities?