Getting the User's Attention with Alerts and Action Sheets
Present important information to the user or prompt the user about an important choice.
Display an alert or action sheet when your app requires additional information or acknowledgment from the user. Alerts and action sheets interrupt your app’s normal flow to display a message to the user. In Figure 1, the left image shows an alert and the right image shows an action sheet. The user dismisses an alert or action sheet by selecting one of the listed options.
To display an alert or action sheet, create a UIAlertController object, configure it, and call its present(_:animated:completion:) method, as shown in Listing 1. Configuring the alert controller includes specifying the title and message that you want the user to see and the actions the user can select. You must add at least one action—represented by a UIAlertAction object—to an alert controller before presenting it.
Present an Action Sheet on iPad
On iPad, UIKit requires that you display an action sheet inside a popover. Figure 2 shows an action sheet anchored to a bar button item.
To display your action sheet in a popover, specify your popover’s anchor point using the popoverPresentationController property of your alert controller. It is safe to configure this property regardless of the underlying device. In other words, Listing 2 displays the action sheet in a popover on iPad and as a slide-up presentation on iPhone.