I am new in swift and now i am stuck in inheritance . Here i am using two class class A, and class B . Class B is inheriting some properties of class A . Here is the code .
class A
{
var objRunningJobs:UIViewController!
var objCompletedJobs:UIViewController!
init(objRunningJobs:UIViewController, objCompletedJobs: UIViewController) {
self.objRunningJobs = objRunningJobs
self.objCompletedJobs = objCompletedJobs
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class B: A
{
override init(objRunningJobs:UIViewController, objCompletedJobs: UIViewController) {
super.init(objRunningJobs: objRunningJobs, objCompletedJobs: objCompletedJobs)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
In class A , after init i am getting the error of 'super.init' isn't called on all paths before returning from initializer .
Short answer:
class A: UIViewController {
let objRunningJobs: UIViewController
let objCompletedJobs: UIViewController
init(objRunningJobs:UIViewController, objCompletedJobs: UIViewController) {
self.objRunningJobs = objRunningJobs
self.objCompletedJobs = objCompletedJobs
super.init(nibName: "TestNib", bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Replace 'TestNib' with yours. But it's a bad way to initialize UIViewController subclass. Probably, you don't understand role of UIViewController's and their hierarchy. What you want to do in your app?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.