How does inheritance work in Swift? In my opinion, all parents should be replaced by their children. For some reason it does not work. The following is an example:
public class Car {
var model: String
func getModel()-> String?{
return model
}
}
public class CompactCar: Car {
}
public class carRedo{
var cartyp:Car!
init(carType: Car){
self.cartyp = carType
}
}
when I pass the CompactCar construct to carRedo, I get a compilation error:
carRedo(CompactCar)
This is mistake:
Cannot convert value of type '(CompactCar) .Type' (aka 'CompactCar.Type') to the expected argument type 'Car'
source
share