O'Reilly logo

Swift 2 By Example by Giordano Scalzo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Geolocalising the app

As a test, we have used dummy coordinates, but we have a powerful GPS on board, and it's time to use it.

Using Core Location

To use the Core Location framework service, we need to instruct iOS that our app is using it.

To do this, we must add the NSLocationAlwaysUsageDescription key with a string; for example, this application requires location services to get the weather of your current location in Info.plist.

Then, we add a new property to PrettyWeatherViewController:

private var locationDatastore: LocationDatastore?

Next, we change the viewWillAppear function:

override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) locationDatastore = LocationDatastore() { [weak self] location in FlickrDatastore().retrieveImageAtLat(location.lat, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required