Join Károly Nyisztor for an in-depth discussion in this video Prepare the fallback logic, part of Swift 4: Protocol-Oriented Programming.
- [Instructor] Now let's implement the fallback logic.…If we build our project right now,…we'll get a compiler error.…This is because we don't provide the backup controller…when instantiating our OpenWeatherMap…network controller instance.…We can fix that easily.…I go back to the OpenWeatherMapNetworkController,…and I provide a default parameter, which is nil.…Since currently our OpenWeatherMapNetworkController…doesn't have a backup, that means that if it fails,…then it reaches the end of the chain.…
That is, there is no other…backup controller to execute the request.…Now the project builds just fine.…All right, now let's simulate a problem.…For that, I will define a helper method.…I call it simulateFailure.…It's a private method,…that returns an optional error…of type…NetworkControllerError.…
I am going to return a fake error…and add an NSError,…with a domain, let's call it after our NetworkController.…I just copy and paste the name here.…Pass in a code of minus one.…And the userInfo can be nil for this case.…When you create your own errors…
- 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.