When I try to execute the code below, I get the following error
error: cannot convert value of type 'X' to specified type 'X'
Doesn't swift support inheritance with generics? Is there a workaround for this?
class Parent{ }
class Child:Parent{ }
class X<T>{
var name: String?
}
var test:X<Parent> = X<Child>() //Compiler Error
P, make classX<T>conform toP. Then usePas return type for your method. You can then return X<Child> as well as X<Parent> from within your method.extension X: P {…}