Skip to content

Instantly share code, notes, and snippets.

@natpenguin
Created September 27, 2020 01:50
Show Gist options
  • Save natpenguin/3713a0a5f1d209943c6a2cd8ab679e0b to your computer and use it in GitHub Desktop.
Save natpenguin/3713a0a5f1d209943c6a2cd8ab679e0b to your computer and use it in GitHub Desktop.
To intercept to pushViewController in UINavigationController
extension UINavigationController {
@objc private func myPushViewController(_ viewController: UIViewController, animated: Bool) {
self.myPushViewController(viewController, animated: animated)
}
static func setupInterceptPushViewController() {
guard let m1 = class_getInstanceMethod(UINavigationController.self, #selector(UINavigationController.pushViewController(_:animated:))) else { return }
guard let m2 = class_getInstanceMethod(UINavigationController.self, #selector(UINavigationController.myPushViewController(_:animated:))) else { return }
method_exchangeImplementations(m1, m2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment