I'm getting an error when trying to execute a segue from a button to a UINavigatinController:
fatal error: unexpectedly found nil while unwrapping an Optional value
@IBAction func displayFootball(_ sender: Any) {
self.configToSend = self.configFootball
performSegue(withIdentifier: "navSegue", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "navSegue" {
let navVC = segue.destination as! UINavigationController
let mainVC = navVC.topViewController as! MainViewController //<--This is where the error occurs
mainVC.config = self.configToSend
}
}
The first segue is called 'navSegue' and the second is unnamed. Both go directly from one view controller to the next (not from the buttons themselves).
The navVC is NOT nil, btw.
Anyone know why this is happening? Thank you.



if segue.identification == "navSegue" { //actions }alsoif let navVC = segue.destination as? UINavigationController { //actions }most probably your navVC is nill - GIJOW