Could not cast value of type to UINavigationController swift3

2744 views ios

I'm getting the following cast error (when I click on the "+" button in the simulator [NavigationController]) and can't figure out why. I'm using Swift3. Thanks for your help!


        protocol AddTaskDelegate: class {
            func saveTask(by controller: AddVC, with data: [String:String])

        class MainVC: UIViewController {
            //    all tasks from the database
            var tasks = [ToDoListTasks]()

            @IBOutlet weak var table: UITableView!

            //    connect with Core Data
            let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

//    prepare segue to send data
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "AddSegue" {
            let navigationController = segue.destination as! UINavigationController
            let childViewController = navigationController.topViewController as! AddVC

            childViewController.delegate = self as! AddTaskDelegate


class AddVC: UIViewController {

    weak var delegate: AddTaskDelegate?

answered question

1 Answer


Just read the error message. You are saying

segue.destination as! UINavigationController

But the destination of this segue is not a UINavigationController.

posted this

Have an answer?


Please login first before posting an answer.