concept implementation in category swift

This is an excerpt from Manning's book Swift in Depth.
Many languages have an implementation of enums, with a different type of implementation per language. Enums in Swift, unlike in C and Objective-C, aren’t only representations of integer values. Instead, Swift borrows many concepts from the functional programming world, which bring plenty of benefits that you’ll explore in this chapter.
You can take this mechanic a bit further and perform inversion of control, or dependency injection, which are fancy words to say that you pass an implementation to a type. Think of supplying an engine to a motorcycle.
You can pass URLSession to your WeatherAPI, but the real power lies in the capability to swap out an implementation. Here’s a fake URLSession that you’ll name Offline-URLSession, which loads local files instead of making a real network connection. This way, you’re not dependent on a backend to play around with the WeatherAPI class. Every time that the dataTask(with url:) method is called, the OfflineURL-Session creates an OfflineTask that loads the local file, as shown in the following listing.
Listing 13.7. Swapping out implementations
let productionAPI = WeatherAPI(session: URLSession.shared) let offlineApi = Weath+rAPI(session: OfflineURLSession())With protocols you can swap out an implementation, such as feeding different sessions to WeatherAPI. If you use an associated type, you can make it represent another type inside the protocol, which can make it easier to mimic a concrete type. You don’t always have to use associated types, but it helps when you can’t instantiate certain types, such as when you want to mock code from third-party frameworks.