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

Chris Jones
STAFF
Chris Jones
Treehouse Guest Teacher

Swift Weather App - Explanation of shorthand .ShortStyle with NSDateFormatter

During the "Cleaning Up Our Date" video of the Build a Swift Weather app, around 6:05 into the video, a NSDateFormatter() is created. To set the time style, Pasan Premaratne set's dateFormatter.timeStyle = .ShortStyle. What looks like a shorthand syntax (.ShortStyle) doesn't make sense to me. It works but I'm unsure of how.

Looking at the docs, NSDateFormatterStyle.ShortStyle is where the constant is defined. So, when working with a NSDateFormatter() instance, how does doing .ShortStyle work? My first guess was that .ShortStyle was a property on the NSDateFormatter but I can't seem to find it.

Any info on how this works would be much appreciated.

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

I had the same question for him when I watched the video! This has to do with enums and will be addressed in full in an upcoming Swift course that is currently in production. Until then, check out this post. We can use a shorthand because the type can be inferred.