Could not cast value of type to UINavigationController swift3

Could not cast value of type to UINavigationController swift3



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!



MainVC.swift


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





AddVC.swift


class AddVC: UIViewController {

weak var delegate: AddTaskDelegate?
...




1 Answer
1



Just read the error message. You are saying


segue.destination as! UINavigationController



But the destination of this segue is not a UINavigationController.






Hey Matt, Thanks for your help.

– Isabell Frischmann
Sep 16 '18 at 23:46



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy