From the course: Swift 5: Protocol-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Integrating a fallback service

Solution: Integrating a fallback service

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

Solution: Integrating a fallback service

(upbeat music) - [Narrator] Welcome back! Hopefully, you have managed to come up with an elegant solution. Let me show you one way to approach this problem. Here's the Web Service Controller. I'm going to add an initializer requirement first. The fallback service parameter is a Web Service Controller and it's optional. By making it optional, we allow callers to set it to nil. This indicates that the controller doesn't have a fallback service. Next, I add the fallback service computed property. It's a type Web Service Controller, and it can be nil. So I make it optional. Now and lets make it gettable only. Clients are not supposed to set its value. And now, I am going to switch to the open ethernet controller, the Swift file. I add the fallback service property first. I declare it as a constant to make it immutable. Next comes the initializer. I provide a default nil value for the fallback service parameter. And…

Contents