How to create alerts in Xcode

Output

You may want to give a warning or additional messages with alerts that let users know their misbehavior in the application. These alerts can be presented using UIAlerts a pop-up that comes in the ios applications. You can also display messages in alert views. In addition to messages, you can link activities to your alert to provide a way for the user to react.

Let's create a small app that displays an alert when a button is tapped.

Step 1: Create a new Xcode Project

Navigate to Xcode Application -> Select create a new Xcode project ->Select iOS on the top, then select single view app and click on next-> Give a Name to your application -> Provide the path to save the application and then click on create

create a new iOS project

Step 2: Add Button

Navigate to main.storyboard press ( command + shift + L ) select button and drag it to the View Controller.

Right-click on the button and press control and drag it to viewcontroller.swift select action and click on connect.

Add button

Step 3: Initiate Alert

Write UIAlertController() function in @IBAction func ButtonTapped

UIAlertController() function invokes alert view when the button is tapped you can provide an alert title, message in the arguments which will be displayed in the alert.

In addition, you can also provide actions that can be performed using addAction() function.

--

--

--

Tech enthusiast i write blogs on Web Development and Mobile app development.

Recommended from Medium

SwiftUI Animate Text Fields

An Introduction to WWLayout

WWLayout logo

Repository Pattern in Swift

The power of Swift + Web Assembly (Part 3)

Clean Swift VIP with Example

What new colors are available in SwiftUI in iOS 15?

color.new.png

New Layer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akshay Devkate

Akshay Devkate

Tech enthusiast i write blogs on Web Development and Mobile app development.

More from Medium

8 key things to know about Native and Hybrid apps

why android app development

How to convert an i18n Google Sheets to iOS Localizable.strings and Android strings.xml?

Best Hybrid Application Development Framework in 2022