I have base class
class Company {
var list: [Employee] = []
var name: String = ""
func getProduct() -> Product {
return Product(name: "Phone")
}
required init(_ list: [Employee], _ name: String) {
self.list = list
self.name = name
}
convenience init?(_ employee: Employee?, _ name: String) {
if ( employee == nil || name.isEmpty) { return nil }
if let emp = employee as? Employee {
self.init([emp], name)
}
self.init(employee, name)
}
}
And inherited
class FoodCompany: Company{
var qualityCertificate: String
required init(_ list: [Employee], _ name: String) {
self.list = list
self.name = name
}
init? (_ employee : (String?, String?), _ name: String, _ qualityCertificate: String ) {
if ( employee.0 == nil || employee.1 == nil ) {
return nil
}
if ( name.isEmpty || qualityCertificate.isEmpty) {
return nil
}
self.qualityCertificate = qualityCertificate
let fName = employee.0 as? String
let lName = employee.1 as? String
}
}
In failable init i have an error 'super.init' isn't called on all paths before returning from initializer. But how i can add super.init calling, if i have no data for it? Maybe i don't understand something? Maybe i need to add init without parameters?
listand thenamethat the superclass initializer requires, don't you? And if that's useless data as far as the superclass is concerned, then it sounds like there's no reason for you to use inheritance here. - Noah