From 0231b63c804e3f8ea757d0ab6d745f9a27ecf4ef Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 20 Feb 2025 10:37:18 -0300 Subject: [PATCH] Prevent EXC_BAD_ACCESS in dismantleUIViewController --- Sources/UIPilot/UIPilot.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/UIPilot/UIPilot.swift b/Sources/UIPilot/UIPilot.swift index ea147c5..ec0944e 100644 --- a/Sources/UIPilot/UIPilot.swift +++ b/Sources/UIPilot/UIPilot.swift @@ -147,8 +147,12 @@ struct NavigationControllerHost: UIViewControllerRep } static func dismantleUIViewController(_ navigation: UINavigationController, coordinator: ()) { - navigation.viewControllers = [] - (navigation as! PopAwareUINavigationController).popHandler = nil + DispatchQueue.main.async { + navigation.viewControllers = [] + if let popAwareNav = navigation as? PopAwareUINavigationController { + popAwareNav.popHandler = nil + } + } } typealias UIViewControllerType = UINavigationController