alexreyes
alexreyes

Reputation: 21

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)

Upvotes: 0

Views: 41

Answers (1)

alexreyes
alexreyes

Reputation: 21

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.

Upvotes: 1

Related Questions