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

Roop P
PLUS
Roop P
Courses Plus Student 6,937 Points

Not clear what I am missing. seems to be correct code

What am I missing here?

enums.swift
enum Compass: Int {
    case north = 1
    case south = -1
    case east = 2
    case west = -2
}
let direction = Compass.south.rawValue

1 Answer

Matthew Long
Matthew Long
28,407 Points

The wording is weird with this question. Basically, as you have it, south has an assigned rawValue of -1, so to assign that to the constant, you need to do the following:

enum Compass: Int {
  case north = 1
  case south = -1
  case east = 2
  case west = -2
}

let direction = Compass(rawValue: -1)

Note that you could have assigned any rawValue you wanted:

enum Compass: Int {
  case north = 0
  case south
  case east
  case west
}

let direction = Compass(rawValue: 1)
Roop P
Roop P
Courses Plus Student 6,937 Points

Matt,

First of all - thank you! As you are the only one who has ever replied to my questions. I wish they improved this process, the questions are to verbose creating complications. TTH needs to give the problem, output and then optional buttons for hints and these explanations.

Matthew Long
Matthew Long
28,407 Points

Sometimes error messages are shown depending on what input has been given. These error messages occasionally show hints as to what might be wrong. This seems to be dependent on who the instructor is.

However, I sort of prefer not having a hints button. I think many people wouldn't try long enough before clicking to reveal a hint. Struggling through something or having real conversations about a concept with someone in the community will help a student actually learn better. This is my opinion though.