UIAlertController in Swift

Balaji Malliswamy
Swift India
Published in
3 min readMay 30, 2018

UIAlertController is one of the most basic component of the app development, because using the UIAlertController to get the feedback, confirmation, choose between the options from the user, also we do alerts.

Components

  • Title : The title of the alert.
  • Alert Message : Descriptive text that provides more details about the reason for the alert.
  • Alert Style : Indicating the type of alert to display.
  • Alert Actions : The actions that the user can take in response to the alert or action sheet.
  • Alert TextField : Text field displayed by the alert.

Alert Styles: Alert Or Action Sheet?

When creating your alert controller, you can choose between two options from enum UIAlertControllerStyle

  1. .alert : An alert displayed modally for the app.
  2. .actionSheet : An action sheet displayed in the context of the view controller that presented it.

Ready? Let’s go, 👨‍💻

Simple alert

Simple action sheet

Alert with distractive button

Alert with more than 2 buttons

Alert with UITextField

If you want to validate the input box, add delegate to the UITextField and you can validate as normally we do for others.

"Good software, like wine, takes time" - Joel Spolsky 🍷

Find it a good read?

Recommend this post (by clicking 👏 button) so other people can see it too…
reach me on Twitter Balaji Malliswamy

--

--

Balaji Malliswamy
Swift India

iOS Engineer, Technical Lead @ivymobility • Writer @ Swift India Publication • Event Organizer @swiftindiagroup meetups. • https://unsplash.com/@blahji