Skip to Main Content
Learning Swift, 3rd Edition
book

Learning Swift, 3rd Edition

by Jonathon Manning, Paris Buttfield-Addison, Tim Nugent
March 2018
Beginner content levelBeginner
378 pages
8h 45m
English
O'Reilly Media, Inc.
Content preview from Learning Swift, 3rd Edition

Chapter 9. Adding Location Info to the Selfies

While we have our selfie app’s basic functionality working like a charm, it isn’t exactly very featureful. As our selfies are each meant to represent a single moment in time, it would be nice to not only know when we took them but also where we took them. So with that in mind, in this chapter we are going to be adding in location support for the selfies, allowing us to save the locations where they were taken.

Visually, we are going to make it so that the map is a small square off to the side of the selfie detail view controller, and when we tap it, it will launch the main Maps application. By the end of this chapter we will have a new feature in our app that will show a small map on each selfie that when tapped will take us to the exact place where the selfie was taken.

To do this we are going to have to add support for locations to our model, add new tests for the updated model, update the UI to support showing a location, and finally configure our project to be able to access the device’s location hardware so we can generate locations.

Updating the Model

The first step is to add location support to the Selfie class and associated methods in the manager, SelfieStore:

  1. Open SelfieStore.swift.

  2. Import the CLLocation class from the Core Location module:

    import CoreLocation.CLLocation
    Note

    Core Location is a large and powerful framework that provides various services for generating and manipulating location-related data. A CLLocation ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning To Program With Swift

Learning To Program With Swift

T. Rogers

Publisher Resources

ISBN: 9781491987568Errata Page