As a birds lover. You want to create a protocol for birds , so when you can use it to create a lot of types of birds that conform to this bird protocole . Follow those steps to acheive your goal:
- Create a new protocol Bird
- protocol Bird has the following properties and method
-
- color : String
-
- wingspan : Int
-
- canFly : Bool
-
- canSwim : Bool
-
- func fly()
- struct Duck
- conform to the protocole properties and functions
- in the fly method : check if it canFly , then print "This Duck is flying!" else print "This Duck Cannot Fly"
- Create a new Duck
- Call the function fly