Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Cory Braun
1,204 PointsWhat's the difference between a rawValue and an Associated Value?
What's the difference between a rawValue and an Associated Value?
1 Answer
agreatdaytocode
24,757 PointsHi cory,
I'll try my best to help you on this. The Swift Apple docs does a nice job of explaining this I think.
Raw values are set to prepopulated values when you first define the enumeration in your code. The raw value for a particular enumeration member is always the same.
Associated values are set when you create a new constant or variable based on one of the enumeration’s members, and can be different each time you do so.
Raw values can be strings, characters, or any of the integer or floating-point number types. Each raw value must be unique within its enumeration declaration. When integers are used for raw values, they auto-increment if no value is specified for some of the enumeration members. For more info see Apple Docs