December 2018
Intermediate to advanced
414 pages
10h 19m
English
We can leverage protocol extensions to provide default implementations for our protocols.
Let's go back to where we were before implementing this whole inheritance chain:
protocol ServicesFactoryType { func getPushService() -> PushNotificationService func getUserLocationService() -> UserLocationService /* Add more services here as your project grows */}
We can just extend that protocol, as follows:
extension ServicesFactoryType { func getUserLocationService() -> UserLocationService { return CommonUserLocationService() }}
We're done—no additional changes, no override keyword to add to the implementations. This strategy has one major drawback, however, compared to the inheritance strategy. In the specific iOS and macOS ...
Read now
Unlock full access