Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Enums and Structs Enums Enum Members and Raw Values

Nick Schumacher
Nick Schumacher
2,729 Points

I am getting an error message that says there is an int expected with the variable I am creating in the challenge.

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

let turtleSpeed = Speed.Slow

wich challenge is this? is it asking you to call slow? if so you for got to call it after you defined it:

if so try:

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

let turtleSpeed = Speed.Slow

turtleSpeed

2 Answers

The variable turtleSpeed is essentially needs to be assigned to the number 10. The member 'Slow' in the Speed enum has a member value of 10. You wrote Speed.Slow but since the variable is an instance of the Speed struct's member Slow which has a value of 10, 'Speed.Slow' only references the enum Speed's member with a name called Slow. However Slow is assigned to an Int value in the enum, which needs to be referenced by using 'rawValue' to refer to the number 10.

enum Speed: Int {
    case Slow = 10
    case Medium = 50
    case Fast = 100
}
var turtleSpeed = Speed.Slow.rawValue

oh never mind hahahaKyle got it