December 2018
Intermediate to advanced
414 pages
10h 19m
English
The final step in our closure-based type erasure is to implement the initializer that will be used to wrap Cows and Goats:
final class AnyAnimal<T>: Animal where T: Food { typealias FoodType = T private let eatBlock: (T) -> Void init<A: Animal>(animal: A) where A.FoodType == T { eatBlock = animal.eat } func eat(food: T) { eatBlock(food) }}
Let's sum up the changes:
Let's ...
Read now
Unlock full access