Skip to content

Instantly share code, notes, and snippets.

@susieyy
Created August 4, 2016 10:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save susieyy/cd1a9fa9def7c3c0c7d1ea1eadf2b876 to your computer and use it in GitHub Desktop.
Save susieyy/cd1a9fa9def7c3c0c7d1ea1eadf2b876 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