Advertisement
tamerSabek

14032019_3

Mar 14th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.40 KB | None | 0 0
  1. import Foundation
  2.  
  3. protocol NoiseMaker{
  4.     func makeNoise()->String
  5. }
  6.  
  7. class Dog: NoiseMaker{
  8.     func makeNoise()->String {
  9.         return "bark"
  10.     }
  11. }
  12.  
  13. class Phone: NoiseMaker{
  14.     func makeNoise()->String {
  15.         return "ring"
  16.     }
  17. }
  18.  
  19. let noiseMakers:[NoiseMaker] = [Dog(), Phone(),Dog(),Dog(),Phone()]
  20. for noiseMakers in noiseMakers{
  21.     print(noiseMakers.makeNoise())
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement