When we create a protocol we can declare some types as generics, this allows to use a different type on each adoption.
Let's look at an example of a protocol where, after defining our Associated Type Item
, we use it to define the type of an array and the parameter of a method.
protocol ListProtocol {
associatedtype Item
var items: [Item] { get set }
func append(item: Item)
}
Continue reading
Access to all the content with our plans.
- Junior level content
- Senior level content
- Expert level content
- Extra content
- Question submissions
Monthly
Yearly
Be the first to comment