Posts

Showing posts with the label constraining associated types

Treehouse Intermediate Course - Part 7 (Generics 5)

Image
The roll continues! So I will do similar to the other week - do several entries within one blog as it may be a bit stop-start. I've got around 20 minutes now just to make a start. By the end of today I will be finished with generics! I will then do a follow up consolidation entry with extra practice before moving on! Start Time - 12:53 Associated Types Can protocols be made generic? It is already in the sense that any type can conform to a protocol. But what about the internal? As in the code that goes behind the scenes... Stack - a bit like an array but more limited. The main point is the order - last in, first out. That makes sense. Associated type for the function - you can use a placeholder name for the type that is used in the protocol. The actual type is not specified until we actually adopt the protocol. Here is the protocol - protocol Stack {          associatedtype Element          mutating func push...