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

Anneke Keller
Anneke Keller
5,667 Points

Swift Enums and Structs first Challenge Task 2 of 2

I can't get it solved. This is my code so far:

Challenge: Create a variable called turtleSpeed and assign it the Raw value of the member Slow.

enum Speed: Int {
    case Slow = 10
    case Medium = 50
    case Fast = 100
}

var turtleSpeed = Speed(rawValue:10)

Can someone help?

4 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Anneke Keller

This challenge wants you to create a variable and add the rawValue of the member Slow. Basically you have to access the enum you created and then use the rawValue from the member Slow. Remember than if you want to access values, you have to use the dot syntax. If you passed this challenge by doing the following, then you passed the challenge correctly, otherwise you may have passed the challenge with an incorrect answer.

enum Speed: Int {
    case Slow = 10
    case Medium = 50
    case Fast = 100
}

var turtleSpeed = Speed.Slow.rawValue

// Here we are accessing one the enum's members rawValue.

Good luck

I didn't realize the challenge could accept an incorrect answer! Thanks for the explanation.

Jhoan Arango
Jhoan Arango
14,575 Points

Lara DiLiberti:

Since you provided the same rawValue to the compiler it assumed it was correct. Remember that the rawValue was an Int, and you gave it an Int for an answer, as it was expecting.

enum Speed: Int {
case Slow = 10
case Medium = 50
case Fast = 100
}

var turtleSpeed = 10
Jhoan Arango
Jhoan Arango
14,575 Points

I modified your answer, so that you code can be read. Nothing in the code was changed :)

Anneke Keller
Anneke Keller
5,667 Points

Thanks! I really appriciate your help.

Anneke Keller
Anneke Keller
5,667 Points

Thanks! Especially for explaining your answer so well.