简体   繁体   中英

TypeMismatch error when instantiating view controller

When trying to instantiate a view controller from my storyboard with instantiateViewController(withIdentifier:) , Xcode throws this error:

typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))

This started to happen I suspect after the most recent Swift patch. Rewinding to an old commit does not fix the problem either. I was able to instantiate other view controllers from the same storyboard but the one in particular always throws this error.

I've tried renaming the view controller's tag, instantiating a different view controller from the same storyboard (this was successful), and cleaning the project

let vc = storyBoard.instantiateViewController(withIdentifier: "map") as! ViewController
self.present(vc, animated: true, completion: nil)

I found the error. If anyone else has an error trying to instantiate a view controller, the class that's instantiated will run its initial lines of code. I assumed it would called viewDidLoad if it was actually calling the view controller, but it will only initialize all of the variables above the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM