I am playing around and learning how to display an alert and I am seeing unexpected behavior
Based on the code snippet below, you can see there is a local variable defined as "result = false".
The alert message is displayed, which asks the user to enter "YES" or "NO"
When I click the "YES" button, I see "YES" text displayed, as expected in the handler
When I click the "NO" button, I see "NO" text displayed, as expected in the handler
Issue:
I never see the "print" in Line 19 displayed ever. What is going on please?
var result = false
let alert = UIAlertController(title: "Testing", message: "Hello", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "YES",
style: .destructive,
handler: { action in
result = true
print("YES")
} ))
alert.addAction(UIAlertAction(title: "NO",
style: .cancel,
handler: { action in
result = false
print("NO")
} ))
present(alert, animated: true, completion: nil)
print("result=\(result)")