Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stormychel/b7c7a4afa9664d685827fb2777c2ea0a to your computer and use it in GitHub Desktop.
Save stormychel/b7c7a4afa9664d685827fb2777c2ea0a to your computer and use it in GitHub Desktop.
Access previous view controller in navigation stack
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