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 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.