NEW: Master Swift design patterns with my latest book! >>


Found 9 articles in the Swift Knowledge Base for this category:


Adding places to MKMapView using MKPlacemark

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 >>

How to add a button to an MKMapView annotation

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 >>

How to add an MKMapView using MapKit

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 >>

How to add annotations to MKMapView using MKPointAnnotation and MKPinAnnotationView

Once you have an MKMapView up and running, it only takes a few lines of code more to drop pins containing placemarks.... Continue Reading >>

How to detect iBeacons

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 >>

How to find directions using MKMapView and MKDirectionsRequest

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 >>

How to make an iPhone transmit an iBeacon

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 >>

How to read the user’s location while your app is in the background

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 >>

How to request a user's location only once using requestLocation

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.

Test your Swift today

Think you know Swift? My book Swift Coding Challenges will put your Swift skills to the test – it's perfect for job interviews and more!

Click here to visit the Hacking with Swift store >>