Overview - Raw values for enums
What is it?
Raw values for enums in Swift are fixed values assigned to each case of an enumeration. These values can be strings, numbers, or other literal types. They allow you to associate a simple, constant value with each enum case for easy identification or storage. This helps enums work smoothly with external data or when you need a specific value for each case.
Why it matters
Raw values exist to connect enum cases with meaningful, fixed data like IDs or names. Without raw values, enums would only represent named options without any direct value, making it harder to save, compare, or communicate enum data outside the program. Raw values make enums practical for real-world tasks like reading from files, databases, or user input.
Where it fits
Before learning raw values, you should understand basic enums and how to define them in Swift. After mastering raw values, you can explore associated values for enums, which allow storing different data per case, and learn about using enums with protocols and pattern matching.