Last active
November 24, 2021 09:14
-
-
Save sunshinejr/d30149bfc38ed8607d1a43fcab77b47d to your computer and use it in GitHub Desktop.
Setup for back/dismiss buttons in VCs, useful for MVVM+C pattern to finish coordinators or don't care about navigation controller and it's dismiss button (whether it's a back button or dismiss or w/e).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIViewController { | |
func dismissOrPop() { | |
if presentingViewController != nil { | |
dismiss(animated: true, completion: nil) | |
} else if navigationController?.presentingViewController != nil, navigationController?.viewControllers.count == 1 { | |
navigationController?.dismiss(animated: true, completion: nil) | |
} else { | |
navigationController?.popViewController(animated: true) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment