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