Skip to content

Instantly share code, notes, and snippets.

@Kdan
Created February 9, 2019 12:36
Show Gist options
  • Select an option

  • Save Kdan/e2da8c82242f7bd7f947833586c15991 to your computer and use it in GitHub Desktop.

Select an option

Save Kdan/e2da8c82242f7bd7f947833586c15991 to your computer and use it in GitHub Desktop.
An example of a boilerplate total distance function for a list of CLLocation objects.
func totalDistance(of locations: [CLLocation]) -> CLLocationDistance {
var distance: CLLocationDistance = 0.0
var previousLocation: CLLocation?
locations.forEach { location in
if let previousLocation = previousLocation {
distance += location.distance(from: previousLocation)
}
previousLocation = location
}
return distance
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment