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

Sean Brown
Sean Brown
986 Points

what am I missing?

I assigned it 10 but I thought 10 was an integer but the error is saying I am not assigning it an integer. What should it be then?

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

var turtleSpeed = Speed(rawValue: 10)

5 Answers

Speed(rawValue: 10) doesn't exists ! You have to assign to turtleSpeed the rawValue of Slow ! If you don't understand watch the video again and come back if you still don't find the answer !

Sean Brown
Sean Brown
986 Points

I thought I did. I thought the rawValue of Slow is 10. Slow is the Member and 10 is it's rawValue. I don't get the question.

You have to get the value, you can't use this value ! Use Slow and take his rawValue :)

Sean Brown
Sean Brown
986 Points

then why does it pass in my Playground?? Why is the instructor able to write a similar line of code in the training?? The challenge never said anything about getting a value. Its just said assign a variable. Is there something missing in the questions? Can someone please help me with the answer so I can learn from it?

screenshot

Sean Brown
Sean Brown
986 Points

jesus on ice skates

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

var turtleSpeed = Speed.Slow.rawValue

well I found this instruction to be very unclear and the video lecture did not show this complete syntax. they did something close in the return statement but didn't use it when assigning it as a variable. I had to utilize the Apple Swift Book to complete the challenge. You would the think the class would teach me what I need to know to pass its own challenges tho.