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

What does "using a raw value with Compass' initializer method" mean in this challenge?

The below code works fine in swift playground and returns the enum rawValue for the enum case south:-

enum Compass: Int { case north = 10 case south = 20 case east = 30 case west = 40 }

let direction = Compass.south.rawValue

Is there a bug in the challenge or is it the use of the use of the Compass' initializer method that causes the challenge to fail? Not really sure I understand exactly what an enums initializer method actually means in plain English.

enums.swift
enum Compass: Int {
    case north = 10
  case south = 20
  case east = 30
  case west = 40
}

let direction = Compass.south.rawValue

2 Answers

Magnus Hållberg
Magnus Hållberg
17,232 Points

The contest say you should use the rawValue initializer, so it should look something like this. let direction = Compass(rawValue: 20)

seemed to work though the challenge mentions assigning Compass.south. Oh well passed the challenge so onwards and upwards. thanks for the help.