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

Raphael Reiter
Raphael Reiter
6,820 Points

enums with raw values code challenge

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

let direction = Compass.south.rawValue

Heres my code, works on xCode ... What's wrong with it? Thanks

enums.swift
enum Compass: Int {
case north = 4
    case south = 1
    case east = 2
    case west = 3
}

let direction = Compass.south.rawValue

3 Answers

David Papandrew
David Papandrew
8,386 Points

Try something like this:

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

let direction = Compass(rawValue: 1)
Harold Sweat
PLUS
Harold Sweat
Courses Plus Student 7,407 Points

I had Raphael's same answer to this question and it did not pass. I also copied David's code in and that didn't pass either.