My project has a:
class BaseViewController: UIViewController
and a:
class PlayerViewController: BaseViewController
I want to add:
init(player playerObject: Player)
to PlayerViewController. According to my googling, and experimenting, I seem to need to have the following in place.
class BaseViewController: UIViewController {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
}
and
class PlayerViewController: BaseViewController {
let player: Player!
init(player playerObject: Player)
{
self.player = playerObject
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Does this make sense? (It just seemed like a lot of 'extra' code) The code that most feels superflous is the init(coder:) initializer in PlayerViewController.
However if I comment it out, I get the compile error:
'required' initializer 'init(coder:)' must be provided by subclass of 'BaseViewController'
I guess I don't see why it's needed when it's not called by the init(playerObject:) initializer I want to add.
any insite would be appreciated.