Enum declaration and cases
📖 Scenario: You are creating a simple app that tracks the weather condition for the day. You want to use an enum to represent different weather types.
🎯 Goal: Build a Swift program that declares an enum called Weather with specific cases, then prints a message based on a selected weather case.
📋 What You'll Learn
Declare an enum named
Weather with cases sunny, rainy, and cloudyCreate a variable named
todayWeather and assign it the sunny case of WeatherUse a
switch statement on todayWeather to print a message for each weather casePrint the message to the console
💡 Why This Matters
🌍 Real World
Enums help represent fixed sets of related values, like weather types, user roles, or app states, making code easier to read and maintain.
💼 Career
Understanding enums is essential for Swift developers building iOS apps, as they are used widely for managing states and options clearly.
Progress0 / 4 steps