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!

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 Network Programming with Swift 2 Modeling Forecast Data Modeling the Current Weather

Harish Yerra
Harish Yerra
10,031 Points

Why aren't we using optionals?

It says in the forecast api docs that the information may be present. As a result, shouldn't we be using optionals since the values could be nil?

1 Answer

Anthony Boutinov
Anthony Boutinov
13,843 Points

The documentation states (and the teacher points it out in the video at about 0:04:20) that some properties are guarantied to be present for currentWeather request, other properties are guarantied to be present at daily forecast, and so on. But overall, when we receive data for any query, we must make sure that each property that wet are interested in is present.

And if we run into a situation where for a given request we got nil values, there is no point in creating CurrentWeather object. Instead, an error must be thrown (and handled, for example by trying to get the data again).