Location

You can add places to any map view using the MKPlacemark class, and it’s different from adding regular annotations – the map view shows the whole address on the map, even from far away, so users can see important points easily.... Continue Reading >>

The built-in MKPinAnnotationView annotation view has a rightCalloutAccessoryView property that can be set to any kind of UIView, including buttons. The button doesn't need to have an action attached to it, because there's a separate method that gets called when it's tapped.... Continue Reading >>

Map views are pretty easy in iOS, largely because they are baked right into Interface Builder. That's right: open your storyboard, drag a map view into your view, and you're already most of the way there!... Continue Reading >>

Detecting iBeacons requires a number of steps. But first you need to decide whether you want to detect beacons only when your app is running, or whether you want beacons to be detected even if your app isn't in the background.... Continue Reading >>

MapKit is great for letting users navigate from place to place, but also makes it easy for you to plot directions from one place to another. You just tell iOS where you're starting from, where you're going, as well as how you're traveling (by car, foot, or mass transit), and it will find routes for you.... Continue Reading >>

iOS 7.0 introduced not only the ability to detect iBeacons, but also the ability to create iBeacons – for iPhones and iPads to broadcast their own beacon signal that can then be detected by other devices. To make this work, you add these two imports:... Continue Reading >>

iOS has had the ability to track locations in the background for some time, but the permission system changed in iOS 8 then again in iOS 11 as Apple has tried to stop unscrupulous apps abusing private information.... Continue Reading >>

iOS has a simple way to request a user's location just once, and it's called requestLocation(). Calling this method returns immediately (meaning that your code carries on executing) but when iOS has managed (or failed) to get a fix on the user's location you will be told. Below is a complete example:... Continue Reading >>

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions, all written for Swift 4.

Go from iOS to macOS the easy way!

If you like Hacking with Swift, you'll love Hacking with macOS – learn to build macOS apps today, using 18 real-world projects!