NEW: Pre-order my Vapor book and learn server-side Swift! >>


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


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

Build for watchOS

Take your existing Swift skills to Apple's tiniest platform – check out Hacking with watchOS!

Click here to visit the Hacking with Swift store >>