Created
August 4, 2016 10:41
-
-
Save susieyy/cd1a9fa9def7c3c0c7d1ea1eadf2b876 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