-
-
Save Oni-zerone/db30fcd8c46ea932ba2322a5d461ffbc to your computer and use it in GitHub Desktop.
Revisions
-
Oni-zerone revised this gist
Dec 18, 2018 . 1 changed file with 14 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,34 @@ struct Dog : Animal { var animalType: String { return "dog" } } protocol Animal { var animalType: String { get } } extension Animal { var animalType: String { return "animal" } func eat() { print("\(animalType) eats") } func talk() { print("\(animalType) talk") } } func animalDoAnimalStuff(animal : Animal) { animal.eat() // eat is defined in extension, thus it is statically dispatched and will print "animal eats" animal.talk() // talk is declared in the protocol, thus it is dynamically dispatched and will print "dog talk" } -
gabrielepalma revised this gist
Dec 18, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ func animalDoAnimalStuff(animal : Animal) { // eat is defined in extension, thus it is statically dispatched and will print "animal eats" animal.talk() // talk is declared in the protocol, thus it is dynamically dispatched and will print "dog talk" } let dog = Dog() -
gabrielepalma created this gist
Dec 18, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ struct Dog : Animal { func eat() { print("dog eats") } func talk() { print("dog talk") } } protocol Animal { func talk() } extension Animal { func eat() { print("animal eats") } func talk() { print("animal talk") } } func animalDoAnimalStuff(animal : Animal) { animal.eat() // eat is defined in extension, thus it is statically dispatched and will print "animal eats" animal.talk() // talk is defined in the protocol, thus it is dynamically dispatched and will print "dog talk" } let dog = Dog() animalDoAnimalStuff(animal: dog)