a function that creates an alert message with custom buttons and text. in swift

Here is an example function that creates an alert message with custom buttons and text in Swift:

main.swift
func showAlert() {
    let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
    
    let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

    alert.addAction(okAction)
    alert.addAction(cancelAction)

    present(alert, animated: true, completion: nil)
}
399 chars
12 lines

This function creates a UIAlertController with a title and message, and adds two custom buttons - "OK" and "Cancel". The user can tap either button to dismiss the alert. To use this function, simply call it from within a UIViewController subclass.

related categories

gistlibby LogSnag