Skip to content

Instantly share code, notes, and snippets.

@agoiabel
Last active January 19, 2018 07:05
Show Gist options
  • Save agoiabel/62c23d30fdca7e968329c5400b3f0e4e to your computer and use it in GitHub Desktop.
Save agoiabel/62c23d30fdca7e968329c5400b3f0e4e to your computer and use it in GitHub Desktop.
func makeSmoothie(with ingredients: [Blendable]) {
for ingredient in ingredients {
ingredient.blend()
}
}
let orange = Fruit(name: "Orange")
let strawberry = Fruit(name: "Strawberry")
let chocolateMilk = Milk(name: "Chocolote")
//This will work perfectly
let ingredients: [Blendable] = [strawberry, chocolateMilk, orange]
makeSmoothie(with: ingredients)
let cheddar = Cheese(name: "Cheddar")
//This will give an error because cheddar
let ingredients: [Blendable] = [strawberry, chocolateMilk, cheddar]
makeSmoothie(with: ingredients)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment