-
-
Save stormychel/b7c7a4afa9664d685827fb2777c2ea0a to your computer and use it in GitHub Desktop.
Access previous view controller in navigation stack
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 { | |
var previousViewController: UIViewController? { | |
guard let navigationController = navigationController else { return nil } | |
let count = navigationController.viewControllers.count | |
return count < 2 ? nil : navigationController.viewControllers[count - 2] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment