Reputation: 5441
I'm running into this error on a viewController and not sure why it's happening. The controller is currently set up like this:
class ContainerViewController: UIViewController {
init(sideMenu: UIViewController, center: UIViewController) {
menuViewController = sideMenu
centerViewController = center
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)// This is where the error happens
}
}
Any clue why this may be happening?
Upvotes: 2
Views: 943
Reputation: 7096
The error is happening in the second initializer because, well, the property isn't initialized. All of your properties that aren't optional and don't have default values have to be initialized separately in each initializer, because only that particular initializer actually runs (unless it explicitly calls a different one).
If you're using the coder
initializer, you'll need to assign it a value in there or make it an optional. If you aren't actually implementing that initializer, leave it with the fatalError
default, since if that ever runs it means something went horribly wrong anyway.
Upvotes: 4