Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Enums and Structs Enums What is an Enum?

Getting error Expected ':' after 'case'. Any ideas?

enum Day{
    case Monday
    case Tuesday
    case Wednesday
    case Thursday
    case Friday
    case Saturday
    case Sunday
}

func weekdayOrWeekend(dayOfWeek: Day) -> String{
    switch dayOfWeek {
        case Day.Monday, Day.Tuesday, Day.Wednesday, Day.Thursday, Day.Friday
            return "It's a weekday"
        case Day.Saturday, Day.Sunday
            return "It's a weekend!"
        default:
            return "Not a valid day"
    }
}

I am using swift 2.0. Is there a new syntax for cases in 2.0? If I add the ':' I just get new errors

1 Answer

Hi Morgan,

The colon goes after the case statement not the keyword:

func weekdayOrWeekend(dayOfWeek: Day) -> String{
    switch dayOfWeek {
        case Day.Monday, Day.Tuesday, Day.Wednesday, Day.Thursday, Day.Friday: //<- here
            return "It's a weekday"
        case Day.Saturday, Day.Sunday: // <- and here
            return "It's a weekend!"
        default:
            return "Not a valid day"
    }
}

That works for me.

Steve.

That was it! Thanks.