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

Julien Schmitt
Julien Schmitt
2,334 Points

Enum: nothing in result sidebar, why?

Hi all,

I'm getting my hands on enumerations.

enum Name { case Julien case Sophie case Jean case Myriam }

enum NameType { case GirlName case BoyName }

func boyOrGirl(name: Name) -> NameType { switch name { case .Jean, .Julien: return .BoyName default: return .GirlName } }

In the function boyOrGirl and for the case .Jean and .Julien, nothing appears in the side bar so I'm guessing I'm doing something wrong.

Could someone tell me why?

Thanks in advance,

Julien

2 Answers

Rodrigo Chousal
Rodrigo Chousal
16,009 Points

Hey Julien,

I tried your code out and everything works as expected. Are you sure you are inputting the enum names correctly?

enum Name {
    case Julien
    case Sophie
    case Jean
    case Myriam
}

enum NameType {
    case GirlName
    case BoyName
}

func boyOrGirl(name: Name) -> NameType {
    switch name {
        case .Jean, .Julien: return .BoyName
        default: return .GirlName

    }
}


boyOrGirl(.Myriam) // Returns GirlName
boyOrGirl(.Jean) // Returns BoyName

Hope this helps, Rodrigo

Julien Schmitt
Julien Schmitt
2,334 Points

Restarted Xcode and now it's returning it...

Thanks for the help Rodrigo.

Cheers,

Julien