Build: Protocol Demo Screen
This screen shows how to use a protocol to make different shapes calculate their area. The user can tap buttons to see the area of a circle or a rectangle.
Target UI
------------------------- | Protocol Demo Screen | |-----------------------| | [Show Circle Area] | | [Show Rectangle Area] | | | | Area: | | | -------------------------
Create a protocol named Shape with a method area() that returns Double.
Create two structs Circle and Rectangle that conform to Shape.
Circle has a radius property; Rectangle has width and height properties.
Add two buttons: 'Show Circle Area' and 'Show Rectangle Area'.
When a button is tapped, display the area of that shape below the buttons.