Am I the only one who’s getting errors after errors when trying this tutorial?
Not sure if the code is not up to date or replaced?
I really really want to do this right, but I get stuck everytime.
I ran the starter project download and the build failed. It failed in AppDelegate.swift line 70. The message says Downcast from ‘NSURL?’ to ‘NSURL’ only unwraps optionals; did you mean to use ‘!’?
The code reads return urls.last as! NSURL
I’m relatively new to Swift. Also, I’m currently going through the MyLocations tutorial.
Maybe I’m missing something here, but it seems like the cumulative distance calculation could overestimate the actual distance. Looking at the code below, whenever the location is updated the location manager gives us an array of locations. There may be only one location in the array, or there could be a few. The function below calculates the distance between each location in the array and the last location. So if there are 3 locations, it calculates the distance between the first location and the last location, then between the second location and the last one. Shouldn’t it be calculating the distance between the first and second, and then between the second and third?
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
for location in locations as! [CLLocation] {
if location.horizontalAccuracy < 20 {
//update distance
if self.locations.count > 0 {
distance += location.distanceFromLocation(self.locations.last)
}
//save location
self.locations.append(location)
}
}
}
Working through the project, I wanted to make a couple modifications to suit my coding style, but for some reason I can’t get the polyline to appear on the map for the tracking of the run. I asked on stack over flow a couple weeks ago but still haven’t gotten a response. wondering if you could assist me with my problem Awesome tutorial, extremely appreciative.
I also upgraded the code to Swift 3/XCode 8.3 (thanks to spitfire4466 for making that code available as I have used some of it). I also changed all the deprecated code to come up to the latest standards. Hope it’s helpful.