In my SwiftUI app I have set in all my views .navigationBarBackButtonHidden(true) to have always a custom Back Button, so the iOS classic swipe to go back has been disabled everywhere, but I actually need it only in specific views.
I re enabled it using this code:
extension UINavigationController: UIGestureRecognizerDelegate {
override open func viewDidLoad() {
super.viewDidLoad()
interactivePopGestureRecognizer?.delegate = self
}
public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return viewControllers.count > 1
}
}
It works but unfortunately it re enables swipe to go back in the entire project, what should I do?