Article
A Core Location Abstraction Layer with Combine and SwiftUI
June 7, 2021

One of the benefits of modern mobile devices is that they can determine your device’s precise location. This enables you to get directions to where you’re going, see nearby restaurants, or view a hyperlocal weather forecast.
On iOS, the Core Location framework gives a developer access to the device’s geographic location and orientation. At an initial glance, this makes it easy to determine the device’s location, with great accuracy.
But as you start to dig into the Core Location documentation, you’ll find that there are a few steps to the process. You have to first request the user’s permission to access the device’s location. Then, if granted, you can request the location. Since determining the device’s location isn’t always instantaneous, you’ll get a callback once a location has been determined.
The Core Location framework uses delegation to asynchronously respond to requests for asking for permission and determining location. Let’s see how this works by implementing a simple SwiftUI view which contains a button for requesting the device’s location.