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 Enums and Structs Enums Enum Members and Raw Values

Raymond Espinoza
Raymond Espinoza
1,989 Points

raw value

How do you assign a variable turtleSpeed to a rawvalue of the member Slow ?

3 Answers

To assign the raw value of Speed.Slow to the "turtleSpeed" variable you would have to do something like the following:

var turtleSpeed = Speed.Slow.rawValue
Raymond Espinoza
Raymond Espinoza
1,989 Points

Thank you Amit didn't explain it like that but when I see assign it does that necessarily mean it's gonna be a = ?

Due to the vagaries of English, it can depend on how the task has been worded.

For example, I could say: "Create a variable called turtleSpeed and set its value to Slow".

However, generally speaking, I would say that you would be correct in assuming that Swift's assignment operator (which is the = sign) should be used if you are being asked to "assign" something.

Hi Raymond,

It sounds like you are asking about Task 2 of the "Enum Members and Raw Values" code challenge.

Please take a look at the "Enum Members and Raw Values" video. Around the 3:50 mark in the video, Amit talks about accessing raw values.

This should help with that code challenge.

However, if it is still not clear how this is being done, please let me know.

-- Ryan

Raymond Espinoza
Raymond Espinoza
1,989 Points

Its asking for a variable though and the videos is showing it as a func?

The key part of that section of the video (in relation to the code challenge) is the part where Amit is accessing the raw value itself.

Amit writes: Day.Saturday.rawValue

This will give you the raw value of the "Saturday" case. You are not limited to using this in a function only, you can use it outside of a function. In your case you want to assign this raw value to a variable.

Please let me know if any further clarification is required, or if you would like you can post the code that you have tried.

Raymond Espinoza
Raymond Espinoza
1,989 Points

I put var turtleSpeed(speed: Speed) -> Int { Return Speed.Slow.rawValue } But still not correct ?