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 Network Programming with Swift 2 Implementing a Forecast Client From JSON to CurrentWeather

Alexander Kvamme
Alexander Kvamme
1,707 Points

How does the completion "bubbling up" work?

What is going on here? Are we bubbling up the APIResult?

Theres a part where he writes completion: completion, and i have struggled for a week to understand the completion handler. I can understand it in simple forms, and i understand that when you write completion(x), you are sending something into what you will later make as a closure, but i dont understand "completion: x"

Can someone explain how i should read these different syntaxes and what really happens here?

Im struggling especially with the "completion: completion" part. What does the two different completion parts refer to?

Thanks :)

Hi Alexander,

When fetchCurrentWeather is called, it needs to get a completion handler as a parameter. I hope this part is clear.

But fetchCurrentWeather does not do much work, it relies on another method doing the work - the one called fetch, which we defined in the APIClient class. So, fetchCurrentWeather calls fetch. Incidentally, fetch also needs to be given a completion handler. So fetchCurrentWeather simply hands over its completion handler parameter to fetch.

The "completion: completion" part which you stated confuses you is simply the third parameter in calling fetch