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 ForecastService

Can someone go over Completion?

I do not fully understand what happens when we do this completion(currentWeather). Could someone elaborate?

also this statement let currentWeather = self.currentWeatherFromJSON(JSONDictionary)

what is the self referring to in here?

what completion(currentWeather) does is executing the function that we pass to getForecast when we call it. For example:

let network = NetworkOperation(...)
network.getForecast() {
  (let response) in 
  println(reponse)
  // The response here will 
  // be currentWheater (which is passed in 
  // on the definition of the method getForecast)
}

So, basically when we call the network.getForecast method, the function that we pass to it, won't be executed until completion(currentWeather) is executed. This is known as a callback.

Thanks! I think I get it better!

I can't give a best answer for some reason tough

1 Answer

seriously...very frustrating..

I to am finding this very frustrating.