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

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

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.