Created
September 29, 2020 14:56
-
-
Save smmcdonald/50f2be5077667f54cdc44a697ab56146 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /// Usage: Pass in the name of the UIViewController you wish to pop back to in the navigation stack. If no matching UIViewController is found, this fails silently. | |
| /// Example: popToViewController(viewController: String(describing: StoreDetailsViewController.classForCoder())) | |
| extension UIViewController { | |
| func popToViewController(viewControllerNamed: String) { | |
| if let viewControllers: [UIViewController] = self.navigationController?.viewControllers { | |
| for view in viewControllers { | |
| if (String(describing: view.classForCoder) == viewControllerNamed) { | |
| self.navigationController?.popToViewController(view, animated: true) | |
| break | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment