How To Display An Alert In iOS & Swift 5

Next Story

How To Use List Of Objects With User Defaults iOS & Swift 4

In iOS, there will be times where you will want to give the user some feedback depending on the situation.

It could be because of a success or a failure whether it be during object creation or authentication.

Below is a code snippet to create an AlertViewController and then present it.

We can add actions to the Alert if we want the user to have additional actions.

We can add this code to any function or lifecycle method that you would like to invoke the Alert Controller.

 

let alertController = UIAlertController(title: "New alert!", message: "User please check out this method", preferredStyle: UIAlertController.Style.alert)

        alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertAction.Style.default,handler: nil))

        self.present(alertController, animated: true, completion: nil)
https://www.googletagmanager.com/gtag/js?id=UA-63695651-4