ios - How would I create a sharedUIAlertView in Swift? - Stack Overflow

PHOTO EMBED

Tue Feb 07 2023 06:27:42 GMT+0000 (Coordinated Universal Time)

Saved by @Raihan #swift

import UIKit
class SharedClass: NSObject {//This is shared class
static let sharedInstance = SharedClass()

    //Show alert
    func alert(view: UIViewController, title: String, message: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        let defaultAction = UIAlertAction(title: "OK", style: .default, handler: { action in
        })
        alert.addAction(defaultAction)
        DispatchQueue.main.async(execute: {
            view.present(alert, animated: true)
        })
    }

    private override init() {
    }
}
content_copyCOPY

https://stackoverflow.com/questions/24022479/how-would-i-create-a-uialertview-in-swift