0
votes

I have a storyboard segue that hooks up VC1 to VC2. The identifier is "showDetail", and the destination ViewController class is YTimeCalendarDetailViewController. When I step through the following in my prepareForSegue, it throws a SIGABRT after failing to if let vc = segue.destination as? YTimeCalendarDetailViewController:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == DETAIL_SEGUE_ID,
        let vc = segue.destination as? YTimeCalendarDetailViewController,
        let selectedDate = selectedDate {
        vc.employeeRecord = selectedJob.employeeRecord
        vc.punches = timesheet[selectedDate]?.punches ?? []
        vc.selectedDate = selectedDate
    }
}

I've tripled checked my segue and viewControllers to make sure that they're pointing at the right things, inheriting from the right class etc. When I print out segue.destination in lldb, it tells me that there is a UIViewController, but I don't know how to find the exact class of the VC. Is this an issue with container views? VC2, contains 3 container views that I intend to show/hide via segmented control. But I doubt it...I'm just so out of ideas.

enter image description here

enter image description here

1

1 Answers

1
votes

You need to assign the class name to the vc in Ib

let vc = segue.destination as? YTimeCalendarDetailViewController,

it's clear from the print <UIViewController:> , select the vc in IB

enter image description here

For an easy debug always use as! instead of as?

let vc = segue.destination as! YTimeCalendarDetailViewController