Create Message Box with completion action

This is to create a method to show message with title in a contain (UIViewController) and when user tap on Close button, completion action, a  closure, will be act  

1. Declare method:

public func showMessage(title : String, message : String, container: UIViewController,  completion: @escaping () -> Void){

        let alertController = UIAlertController(title: "", message: message , preferredStyle: .alert)

        //the cancel action doing nothing

        let doneAction = UIAlertAction(title: "Close", style: .default) { _ in

            completion()

        }

        alertController.addAction(doneAction)

        container.present(alertController, animated: true, completion: nil)

    }


2. Call the method:


showMessage(title: "Title", message: "message", container: theUIViewController){

          // call method or closure with type () -> Void

        // self.OpenJobOrTaskListScreen()

 }

Comments

Popular posts from this blog

return value to controller caller

Apple Push Notification Service APNS

Delivery In House iOS app