'Swift: How to call two times the same alert from another alert?

I have simplified my problem to the following code where the same behavior occurs.

What I want to do is calling a method which includes an alert (messageWindow() in my code) two times which means one behind the other. I want to call that method from another method which also includes an alert (userInput()) in my code.

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(_ animated: Bool) {
        userInput()
    }
    
    func userInput() {
        let alert = UIAlertController(
            title: "Welcome",
            message: "Do you want say hello?",
            preferredStyle: .alert)
        let actionYes = UIAlertAction(
            title: "Yes",
            style: .default) {_ in
                print("hello")
                self.messageWindow(title: "1st call", message: "Hello!")
                self.messageWindow(title: "2nd call", message: "Hello!!")
            }
        let actionNo = UIAlertAction(
            title: "No",
            style: .default) { (action) in }
        alert.addAction(actionYes)
        alert.addAction(actionNo)
        self.present(alert, animated: true)
    }
    
    func messageWindow (title: String, message: String) {
        let alert = UIAlertController(
            title: title,
            message: message,
            preferredStyle: .alert)
        let actionOk = UIAlertAction(title: "OK", style: .default) { (action) in }
        alert.addAction(actionOk)
        self.present(alert, animated: true)
    }
}

My problem is that the second call won't be executed (code snippet below). That means I don't see a window popping up like in the first call.

self.messageWindow(title: "2nd call", message: "Hello!!")

I'm relative new in coding with Swift. Please excuse my question in case it is a really simple one. I didn't found anything which helped me solving this problem.

I appreciate your help. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source