I have created a ViewController which is a subclass UIViewController. I have some properties which are defined nullable as shown below:
// CloudKit
let container :CKContainer?
let publicDB :CKDatabase?
Now, I initialize it using the init constructor method and Xcode complains that I also need to override the initWithCoder constructor which in my opinion feels kind of unnecessary.
init() {
container = CKContainer.defaultContainer()
publicDB = container!.publicCloudDatabase
super.init(nibName: nil, bundle: nil)
}
required init(coder aDecoder: NSCoder) {
container = CKContainer.defaultContainer()
publicDB = container!.publicCloudDatabase
super.init(coder: aDecoder)
}
I end up with lot of duplicate initialization code for container and publicDB as you can see above.
Is there a better way of doing the same as I have done?