Is it possible to have a generic protocol in swift? I tried protocol foo<T>{}
and that is not legal. I'm looking for something that can be used similarly to Java's List<T>
interface.
There is no such thing as generics for protocols. But there is something else, which ressembles a lot to the generics when you look at it.
Here is an example taken from the Swift standard library:
protocol Generator {
typealias Element
func next() -> Element?
}
The Swift book scratches the surface in the Generics chapter, Associated Types.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments