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 Intermediate Swift 2 Properties Reading Modes

Boris Likhobabin
Boris Likhobabin
3,581 Points

Is there a convention?

var headlineColor: UIColor { switch self { case Night: return UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) case .Evening, .Day: return UIColor(red: 16/255.0, green: 16/255.0, blue: 16/255.0, alpha: 1.0) }

This is the code snippet from the video... As you may notice there is a typo in list of cases: Before all the cases in this video there is a dot eg. case .Evening, .Day but before Night there is no dot, and there is no errors in the compiler. I guess (but not sure) it makes no diffrence. However what is the RIGHT way of switching on self? with the dot or without?

1 Answer

David Lin
David Lin
35,864 Points

Not sure if there is a "right" way. As you noted, both ways work. Personally, I think it's clearer if the dot is used, because doing so explicitly states that what's being referred to is an enum case.