April 2026
Intermediate
683 pages
25h 29m
English
First and foremost, Swift protocols can enforce concrete classes to implement certain functions. That way, protocol clients can rest assured that the underlying concrete class will support that function without knowing the implementation details. In this section, we will go over different case studies to discover how. This will also be the hands-on debut of protocol syntax.
To learn about nonmutating functions, let’s implement the LLM case study introduced earlier. The sample application will feature the ability to talk to multiple LLMs—or at least pretend to do so.
For that purpose, Listing 10.1 features a simple protocol called LangModel, with a single function.
protocol LangModel ...
Read now
Unlock full access