I Created a subclass of UIAlertController which do some stuff but befor dimissing it i call Delegate (is a custom protocol for delegation pattern to use this in UIViewController) right befor dimiss statement
- Inserted this Code in my Custom Alert Class.
- I have a strong reference from it in UIViewController and set delegate to self.
- Conforming protocol and set a break point never reached during runtime.
// this code in my custom subClass of UIAlertController
func addRequestAction() {
addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak self] _ in
self?.checkConnection { isConnected in
print("xxxxxxxxx", isConnected)
DispatchQueue.main.async {
if isConnected {
self?.delegate?.didConnect() // here i call delegate function but never executed
self?.dismiss(animated: true, completion: nil)
} else {
let alert = NetworkCheckerAlert(self?.delegate)
self?.dismiss(animated: true, completion:nil)
guard let viewController = UIApplication.shared.keyWindow?.rootViewController else { return }
viewController.present(alert, animated: true, completion: nil)
}
}
}
}))
}