Last active
January 19, 2018 07:05
-
-
Save agoiabel/62c23d30fdca7e968329c5400b3f0e4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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