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
:
-
Open SelfieStore.swift.
-
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 ...
Get Learning Swift, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.