Imagine an app used by a fast food restaurant. The management has decided to show calorie counts for the meals being served. The app currently has the following class, structure, and enumeration, and none of them have calorie counts implemented:
- A Burger class
- A Fries structure
- A Sauce enumeration
Let's see how you can add calorie counts to all three, and later write a function to calculate the total calorie count.
Type in the following code and run it:
class Burger {
}
struct Fries {
}
enum Sauce {
case chili
case tomato
}
These represent the existing class, structure, and enumeration in the app. Don't worry about the empty implementations, as they are not required for this lesson. As you can see, none of them have calorie counts.
You will solve this problem by using protocols. A protocol is like a blueprint that determines what properties...