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!

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 Enumerations and Optionals in Swift Objects and Optionals Enums with Raw Values

Sam Belcher
Sam Belcher
3,719 Points

Enums 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) {

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi 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)

:bulb: 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.