Kodeco Forums

How To Make an App Like RunKeeper with Swift: Part 1

Learn the basics of Core Location and tracking runs on a map in the first of this two-part tutorial on building an app like RunKeeper!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1745-how-to-make-an-app-like-runkeeper-with-swift-part-1

Hi guys!

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.

any help?

Thanks!
Glenn

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.

Thanks,

Josh

Just use

return urls.last!

you could be safe and check that the unwrap works by doing like

if let lastURL = urls.last {
return lastURL
}
// return nil or throw error

urls.last is an NSURL? and I guess in older versions of swift you had to cast, but now you can just unwrap.

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)
}
}
}

trying to execute this after few errors, worked but map never show a street view, a non zoomed for the country.
any ideas? how to fix it?

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 :smiley: Awesome tutorial, extremely appreciative.

I rewrote this project into Swift 3. I will post it sooner or later on my github. /pawisoon

Thanks for the great tutorial!
Also updated the code to Swift3 and Xcode 8.2 if that can be of use to anyone.

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.