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 with Swift Managing Complexity Methods with Closures

I dont understand why we want the downloadJSONFromURL method to return void - dont we want it to return a Dictionary?

Dont we want downloadJSONFromURL to give us a dictionary to use in the same way that we used the plist earlier. I dont quite understand why we would want it to return void. Thanks for the help!!!

1 Answer

It's because the downloadJSONFromURL method makes an asynchronous network request. This means the function will complete before the network request returns a response. As a result, rather than returning the JSON data from the function like with a synchronous function, instead it is passed to a callback closure, in this case the completion argument of the method.

One of the earlier videos in this series talks about concurrency - I recommend you rewatch this if you don't understand the concepts of asynchronous code.