Chapter    11

Generic Programming

Up to this point in this book, function and method parameter and return value types have been explicitly specified. Overloading offers a way to define multiple functions that share the same signature except for varying parameter and/or return value types. And protocols provide for declaring a set of requirements that an adopting type must contractually fulfill. Yet there is one more feature of Swift that may at first feel like a mere combination of aforementioned capabilities; however, in due time, it may prove to be one the most powerful features of the language: generics. As much as the Swift standard library is made up of protocols and extensions, generic types are more abundantly used than the other two combined. ...

Get Transitioning to Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.