I am trying to make an alert on my app, but it keeps giving me warning like the below and it's not appearing
Warning: Attempt to present <UIAlertController: 0x..> on <xyz.VC1: 0x..> whose view is not in the window hierarchy!
the logic is like this :-
the IBAction
in (VC1) calls a public function (X)
(X) the function do some operation and functions and based on it it's called the public function (Alert)
(Alert) the function should present an alert, but it gives me the previous warning.
NOTE: the alert works fine if I use it directly from the IBAction
present the alert :
func WAlert(){
// print("Wrong :("") // to be an alert
let alert = UIAlertController(title: "S?", message: "Y", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "C", style: UIAlertAction.Style.default, handler: { _ in
//Cancel Action
}))
alert.addAction(UIAlertAction(title: "out",
style: UIAlertAction.Style.default,
handler: {(_: UIAlertAction!) in
//Sign out action
}))
present(alert, animated: true, completion: nil)
//self.present(alert, animated: true, completion: nil)
//VC1.present(alert, animated: true, completion: nil)