Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Enumerations and Optionals Objects and Optionals Enums with Raw Values

Paul Je
Paul Je
4,435 Points

So Close..

Not sure where I can improve this, it's kind of the most complex version of the combination of code I tried, is it more simpler than this? I tried on Xcode and seems to be working fine on all counts..

enums.swift
enum Compass: Int {
  case North = 1
  case South = 2
  case East = 3
  case West = 4
}

let direction = Compass.South.rawValue {

if let checkTheCompass = Compass(rawValue: direction) {
print(checkTheCompass)
}

1 Answer

Paul, not quite. You use rawValue a different way, i.e. with Compass' initializer method and the value.:

let direction = Compass(rawValue: 2)

No need for if or print.