Created
February 9, 2019 12:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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