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

Meg Cusack
Meg Cusack
11,448 Points

Swift> Control Flow> Switch statement quiz question

In the switch statement quiz, the second question, I got it correct but why did he put in the end of the correct answer code "default: println(month)"? I thought you only need to put in the default if the cases are not exhaustive? The 4 cases in that answer already covered all other possibilities for cases.

1 Answer

I'm not sure exactly what question you're referencing, but I would say use a default fallback no matter what. Over time a value can change in a program, and you don't want bugs caused due to this. Taking the time to enter those few lines can save you a lot of headache later on in a project as it grows. Indeed, it is optional, and if the challenge used it though it isn't needed, it's likely to reinforce good habits.

Meg Cusack
Meg Cusack
11,448 Points

Thanks, very helpful.