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 trialSam Belcher
3,719 PointsEnums With Raw Values (Swift)
What am I doing wrong?
enum Compass: Int {
case north = 100
case south = 200
case east = 300
case west = 400
}
let southern = 200
if let direction = Compass(rawValue: southern) {
print(direction)
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're doing pretty well, I think but you did some things the challenge wasn't expecting. First, you're using an if let
that wasn't asked for, implementing a variable that wasn't asked for, and you're printing when it didn't ask for anything to be printed.
I simplified your code to one line. Take a look:
let direction = Compass(rawValue: 200)
Going forward, it's a good idea to try not to do anything the challenge doesn't explicitly ask for. Even if functional, it can break the challenge or no longer meet its exacting requirements.