Could not cast value of type 'UITableViewController'

I keep getting this error message

Could not cast value of type 'UITableViewController' to SecondViewController

I honestly have no clue please help

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     var destination = segue.destination as! SecondViewController
     destination.myString = outputName.text!
}

on the 'var' line but is now on the override 'func line' i have litterally no clue what it means.

3 answers

  • answered 2019-07-18 15:26 Sh_Khan

    For this

    var destination = segue.destination as! SecondViewController
    

    to avoid crash you need to set class name SecondViewController to the destination vc in storyboard assuming

    class SecondViewController:UITableViewController {}
    

  • answered 2019-07-18 16:56 Shivang Pandey

    class SecondViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate,UITableViewDelegate,UITableViewDataSource {
    

    I hope this will work.

  • answered 2019-07-19 09:04 Sam Brookes

    So i solved it! I had the class on the second ViewController punctuated wrong i forgot the capital S