func eat<T: Food>(_ food: T) {
print("I sure love \(food.menuListing).")
}
eat(Bread())
struct Restaurant {
private struct SlicedFood<Ingredient: Food>: Food {
var food: Ingredient
var menuListing: String {
"a slice of \(food.menuListing)"
}
}
private struct CookedFood<Ingredient: Food>: Food {
var food: Ingredient
var menuListing: String {
"\(food.menuListing), cooked to perfection!"
}
}
func makeSlicedBread() -> Food {
return SlicedFood(food: Bread())
}
func makeToast() -> Food {
let slicedBread = SlicedFood(food: Bread())
return CookedFood(food: slicedBread)
}
}
let restaurant = Restaurant()
let toast = restaurant.makeToast()
eat(toast)
After making the changes in listing 21.29, that last line of code eat(toast)
errors:
Value of protocol type ‘Food’ cannot conform to ‘Food’; only struct/enum/class types can conform to protocols.
I’ve gone over this a few times and nothing is jumping out at me. Did others get this working?