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 Review Enums

I don't believe this is an invalid declaration: enum genre { case drama, romance, satire, tragedy, comedy }

It seems this is just an example of not following best coding practises. It works fine in Xcode, therefore must be a valid declaration. Right?

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Antony,

The code you have is a valid declaration but coding standards in Swift say enum's must start with an uppercase letter for both the name and values excluding functions contained within the enum.

// Incorrect
enum genre { 
    case drama, romance, satire, tragedy, comedy 
}

// Incorrect
enum Genre { 
    case drama, romance, satire, tragedy, comedy 
}

// Incorrect
enum genre { 
    case Drama, Romance, Satire, Tragedy, Comedy 
}

// Correct
enum Genre { 
    case Drama, Romance, Satire, Tragedy, Comedy 
}

Hope that helps.

Great, you're right. I raised this because the test at the end of the course asked me to select a valid option, and this was an example of an invalid option. I agree it doesn't follow coding standards, but it's not wrong! :)