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 trialSteffen Alexander Ness
11,076 PointsEnum rawValue code does not pass
I need some help figuring out why this code does not pass.
enum Compass {
case north = 1
case south = 2
case east = 3
case west = 4
}
let direction = Compass.south(rawValue: 2)
1 Answer
Clark Reilly
6,204 PointsThe enum needs to be assigned a raw value type of Int
enum Compass: Int {
// cases are fine
}
Also
Compass.south doesn't have an initializer, you need to call it on Compass:
let direction = Compass(rawValue: 2)
Steffen Alexander Ness
11,076 PointsThanks :)
Steffen Alexander Ness
11,076 PointsSteffen Alexander Ness
11,076 PointsI get this error: "Bummer: Make sure you're creating an enum value using the raw value initializer and assigning the result to direction"