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 Build a Weather App Dark Sky API Client From JSON to CurrentWeather

Will Matthews
Will Matthews
8,127 Points

Why define the CurrentWeather extension in the CurrentWeather file?

I'm curious about why we'd want to define the CurrentWeather extension in the CurrentWeather file itself. Given that the keys we're defining are likely unique to the API we're using, why wouldn't we define this extension in the DarkSkyAPIClient file instead?

3 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

Did you attempt to do that to see what happens?

Will Matthews
Will Matthews
8,127 Points

I did. I can't seem to spot an problems in doing so just yet. Unless they're subtle?

Jeff McDivitt
Jeff McDivitt
23,970 Points

If there are no issues it would really just be program preferance.

I believe it is due to preference and clarity of code, remember that the extension is used to conform to the CustomStringConvertible so he abstracted it out in to extension to reflect that he is going to use the description property. Just easy to read :)