Swift: Custom ViewController initializers
Solved it! One has to call the designated initializer which in this case is the init with nibName, obviously ...
init(leftVC:UIViewController, rightVC:UIViewController, gap:Int){ self.leftVC = leftVC self.rightVC = rightVC self.gap = gap super.init(nibName: nil, bundle: nil) setupScrollView() setupViewControllers()}
For a more generic UIViewController you can use this as of Swift 2.0
init() { super.init(nibName: nil, bundle: nil)}
Swift 5
If you want to write custom initializer to UIViewController
which is initialized with storyBoard.instantiateViewController(withIdentifier: "ViewControllerIdentifier")
You can write custom initializer for only Optional
properties.
class MyFooClass: UIViewController { var foo: Foo? init(with foo: Foo) { self.foo = foo super.init(nibName: nil, bundle: nil) } public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.foo = nil }}