As per the talk, we have the following example:
protocol Animal {
associatedtype CommodityType: Food
func produce() -> CommodityType
}
protocol Food {}
struct Farm {
var animals: [any Animal]
func produceCommodities() -> [any Food] {
let produce = animals.map { animal in
// animal has type Animal
animal.produce()
}
// produce has type [Food]
return produce
}
}
In the video(03:51) the lecturer goes on to explain that the type of animal is any Animal but when I wrote the same code I can clearly see that the type is Animal - thus what happened to the existential ? The same goes for the return type of produce - I was expecting the type of the value to be any Food but it is Food.
Anyone can explain the reason for the mismatch between what is shown in the lecture and what the compiler shows ? Using Xcode 14.2
1
0
789