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

Kevin Gonzales
Kevin Gonzales
4,638 Points

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?

Erwin Gaitan Ospino
Erwin Gaitan Ospino
3,102 Points

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.

Kevin Gonzales
Kevin Gonzales
4,638 Points

Thanks! I think I get it better!

Kevin Gonzales
Kevin Gonzales
4,638 Points

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

1 Answer

Frank Novello
Frank Novello
19,299 Points

seriously...very frustrating..

Brian Patterson
Brian Patterson
19,588 Points

I to am finding this very frustrating.