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 trialRichard Pitts
Courses Plus Student 1,243 PointsThought this was correct?
Thought this was correct?
enum Compass: Int {
case south
case east
case north
case west
}
let direction = Compass.south.rawValue
1 Answer
David Papandrew
8,386 PointsHi Richard,
*UPDATED ANSWER* Whoops, as Raphael pointed out, I made a mistake in my response.
Here is the corrected code:
enum Compass: Int {
case north = 1
case south
case east
case west
}
let direction = Compass(rawValue: 2)
*ORIGINAL RESPONSE*
The Compass enum is missing a couple of items:
1) The enum's raw value should be String not Int
2) The enum cases should each have raw values assigned
Once you have set these items up, you can instantiate the enum object properly. See the code below:
enum Compass: String {
case north = "North"
case south = "South"
case east = "East"
case west = "West"
}
let direction = Compass(rawValue: "South")
Raphael Reiter
6,820 PointsRaphael Reiter
6,820 PointsHi David Papandrew , I dont understand. Pasan says: Let's get in some practice creating enums with raw values. Declare an enum named Compass with a raw value of type Int.
he also say to use : Assign the enum value Compass.south to a constant named direction, by using a raw value with Compass' initializer method.
David Papandrew
8,386 PointsDavid Papandrew
8,386 PointsYou are right Raphael, I've updated the response above.