concept associated type in category swift

This is an excerpt from Manning's book Swift in Depth.
Once Swift has you hooked, you’ll likely hit speed bumps in the shape of generics and associated types, and something as “simple” as handling strings may cause more trouble than you might expect (see figure 1.2).
You’ve seen two alternatives that were not the real solutions to your problem. You’ll create a viable solution to the problem. You’re going to follow the compiler’s advice and use associated types. You can rewrite Worker and use the associatedtype keyword, where you declare both the Input and Output generics as associated types.
Listing 8.15. Worker with associated types
protocol Worker { #1 associatedtype Input #2 associatedtype Output #2 @discardableResult func start(input: Input) -> Output #3 }Now the Input and Output generics are declared as associated types. Associated types are similar to generics, but they are defined inside a protocol. Notice how Worker does not have the <Input, Output> notation. With Worker in place, you can start to conform to it for both MailJob and FileRemover.
Associated types are generics that are tied to a protocol. Protocols with associated types allow a concrete type to define the associated type. Each concrete type can specialize an associated type to a different type. Protocols with Self requirements are a unique flavor of associated types referencing the current type. Protocols with associated types or Self requirements force you to reason about types at compile time.
You introduce a new Song type, but instead of playing a file at a URL, it uses an AudioFile type. How would you deal with this? See if you can make the protocol reflect this. Answer: You introduce an associated type, such as Media. The contents property is now of type Media, which resolves to something different for each implementation: