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 trialLana Wong
3,968 PointsI do not understand why my enum initializer isn't working?
In this challenge, I did what Pasan did and it worked on Xcode too. I do not understand what is wrong with my code.
enum Compass: Int {
case north = 1
case south = 2
case east = 3
case west = 4
}
let value = 2
if let direction = Compass(rawValue: value){
print(direction)
}
1 Answer
ceriannejackson
23,759 PointsThere's no need to use if let as you know you can initialise the enum with a raw value of 2 and you're not using direction afterwards. So, you can simplify your code to:
let direction = Compass(rawValue: 2)