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

iOS Swift 2.0 Enumerations and Optionals Objects and Optionals Initializing With Raw Values

Whats the difference between an enum's stored property's default value and rawValue?

For example:

enum HTTPStatusCodes: Int {

case Continue = 100
case Success = 200
case Unauthorized = 401
case Forbidden = 403
case NotFound = 404

} case Continue = 100 is both a rawValue and default value?

2 Answers

They are the same.

Apple documentation: "enumeration cases can come prepopulated with default values (called raw values), which are all of the same type."

Hi there is no difference at all.

Enum Members can have default values which are known as raw values. Raw values can only be certain types. These types include strings, Integers, Characters and Floating point Numbers.

Associated values are set when you create an enum and they can be different values for every instance including custom types.