Skip to content

Instantly share code, notes, and snippets.

@vdeep
Created June 15, 2022 12:31
Show Gist options
  • Save vdeep/f89996d25fc7c47a92a473e3daf571c0 to your computer and use it in GitHub Desktop.
Save vdeep/f89996d25fc7c47a92a473e3daf571c0 to your computer and use it in GitHub Desktop.
Completion block support for UINavigationController push and pop methods
import UIKit
extension UINavigationController {
func pushViewController(viewController: UIViewController, animated: Bool, completion: @escaping () -> Void) {
pushViewController(viewController, animated: animated)
if animated, let coordinator = transitionCoordinator {
coordinator.animate(alongsideTransition: nil) { _ in
completion()
}
} else {
completion()
}
}
func popViewController(animated: Bool, completion: @escaping () -> Void) {
popViewController(animated: animated)
if animated, let coordinator = transitionCoordinator {
coordinator.animate(alongsideTransition: nil) { _ in
completion()
}
} else {
completion()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment