Reputation: 804
In C++, I can implement it like this.
template<typename MyType>
class MyClass : public MyType
{
};
Is it possible to do so in Swift?
///Compiler error: Inheritance from non-procotol, non-class type 'T'
class MyClass<MyGeneric> : MyGeneric
{
}
Upvotes: 0
Views: 69
Reputation: 42129
You have to use your class as a constraint. The way you wrote it makes MyGeneric a placeholder name (and not a reference to the class with the same name):
class MyClass<T:MyGenericClass>:MyGenericClass
{}
This is assuming that what you're trying to get is something like this:
class MyGenericSubClass: MyGenericClass {}
let c = MyClass<MyGenericSubClass>()
Upvotes: 1