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

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