Search code examples
swiftsegueuistoryboarduistoryboardsegue

unexpected segue error found nil


I get this error when pressing the home button: Thread 1: Fatal error: Unexpected Segue Identifier; nil

This is my code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    super.prepare(for: segue, sender: sender)

    switch(segue.identifier ?? "")
    {

    case "AddItem":
        os_log("Adding a new day.", log: OSLog.default, type: .debug)

    case "ShowDetail":
        guard let newDayDetailController = segue.destination as? newDayController else {
            fatalError("Unexpected destination: \(segue.destination)")
        }

        guard let selectednewDayCell = sender as? newDayTableViewCell else {
            fatalError("Unexpected sender: \(String(describing: sender))")
        }

        guard let indexPath = tableView.indexPath(for: selectednewDayCell) else {
            fatalError("The selected cell is not being displayed by the table")
        }

        let selectedDay = days[indexPath.row]
        newDayDetailController.day = selectedDay

    case "toMenu":
        os_log("Back to main menu", log: OSLog.default, type: .debug)


    if segue.identifier == "sendData"
    {
        let VC = segue.destination as! HomeViewController

        VC.data = totalDays!

    }

    default:
    fatalError("Unexpected Segue Identifier; \(String(describing: segue.identifier))")
    }
}


//MARK: Actions

@IBAction func menuButton(_ sender: Any) {

    performSegue(withIdentifier: "sendData", sender: self)

}

Someone please help me out?


Solution

  • Make sure to set the segue identifier in the Attributes Inspector in your storyboard

    Attributes Inspector

    Apparently your switch statement goes to the default case.