I've been attempting to follow a tutorial about creating a container view controller. It's in Objective-C. I want to convert it to Swift. I've found some of the same questions here, but I didn't get too much out of them.
Here's the code.
import UIKit
class ContainerViewController: UIViewController { // Class "ContainerViewController" has no initializers - That I know why.
// 'required' initializer 'init(coder:)' must be provided by a subclass of UIViewController
var currentDetailViewController: UIViewController
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
I've tried doing what both errors say, but still doesn't work.
The problem is: If you declare any stored properties without initial value, you must implement your own initializer to initialize them. see this document.
Like this:
But, I think this is not what you want.
The correct solution depends on where you initialize
currentDetailViewController
.If you always initialize it within
viewDidLoad
, then you can declare it as an "Implicitly Unwrapped Optional"otherwise, If
currentDetailViewController
can benil
, you should declare it as an "Optional"