- [Instructor] Let's get back to…the fetchCurrentWeatherData method.…The method fetches data from the internet.…This means that it won't return instantly.…The response times may vary…depending on various factors,…like the network speed, sever load, and so on.…Such long-running tasks should be implemented…as asynchronous methods.…Swift makes it easy to implement asynchronous methods.…Instead of using a return value,…we can use a completion handler.…Completion handlers are blocks of code…that get executed…when the asynchronous method finishes.…
So let's change the signature of…the fetchWeatherData method…to include a completion handler.…I'm going to add the completion handler here…as a second parameter.…I mark the completion handler as escaping.…In Swift 3 and above,…a closure that is passed as an argument or function…is non-escaping by default.…Non-escaping means that the closure…is invoked before the function returns.…In our case, this won't be true.…
The fetchCurrentWeatherData method…will always return before the actual…
- Comparing object-oriented programming with protocol-oriented programming
- Methods and class-bound protocols
- Adopting a protocol
- Declaring asynchronous behavior
- Preparing and implementing fallback logic
- Implementing an app using protocol-oriented programming
Skill Level Intermediate
1. Protocol-Oriented Programming
4. Implement the Weather App Using POP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.