Heres my class hierarchy:
class Parent {
var name: String
var age: Int
init(dict: [String: Any]) {
age = dict["age"] as! Int
}//ERROR: "Return from initializer without initializing all stored properties"
}
class Child: Parent {
var school: String
override init(dict: [String: Any]) {
school = dict["school"] as! String
super.init(dict: dict)
name = dict["childname"] as! String
}
}
If I initialise name
property in Parent
initialiser then it's working, but in my situation I want it to initialise in Child
only.
Is there any way to handle this?
P.S. there are lots of properties in Parent
like name
those should be initialised in Child