phnmnn
phnmnn

Reputation: 13240

Generic class inheritance in Swift - Compile error

The following Swift code does not compile:

class A<T:Codable> {

}

class C<T: Codable> : A<T: Codable> { //Expected '>' to complete generic argument list

}

I get the following error:

"Expected '>' to complete generic argument list"

Please help.

Upvotes: 1

Views: 311

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

You need

class A<T:Codable> {

} 
class C<T: Codable> : A<T> {

}

When you do class A<T:Codable> with C<T:Codable> that means the object inside <> conforms to Codable so when you make it as a parent class you put the name of the object to be used without redundantly adding : Codable

Upvotes: 2

Related Questions