I figured it out, it was my programming mistake and lack of proper sleep :). Another VC which was listening for notifications about the result of the same fetch was triggering a popup even though it was not visible, but was alive, embedded in a tab bar controller. So my "failure" popup was never executed properly. I figured it out after I updated the showModal method with the sender parameter and following that I have added a fix that requires the calling VC to be visible when it wants to present a popup:
func showModal(sender: UIViewController, title: String, msg: String, handler: ((UIAlertAction) -> Void)? = nil) {
let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: handler))
DispatchQueue.main.async {
if sender.isVisible() {
self.present(alert, animated: true, completion: nil)
}
}
}
where isVisible():
extension UIViewController {
func isVisible() -> Bool {
return self.isViewLoaded && self.view.window != nil
}
}
Topic:
Programming Languages
SubTopic:
Swift
Tags: