Swift Generics Tutorial: Getting Started

Learn to write functions and data types while making minimal assumptions. Swift generics allow for cleaner code with fewer bugs. By Michael Katz.

4.8 (43) · 1 Review

Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Where to Go From Here?

Swift generics are at the core of many common language features, such as arrays and optionals. You’ve seen how to use them to build elegant, reusable code that will result in fewer bugs — code fit for royalty.

For more information, read through the Generics chapter and the Generic Parameters and Arguments language reference chapter of Apple’s guide, The Swift Programming Language. You’ll find more detailed information about generics in Swift, as well as some handy examples.

A good next topic, to build upon what you’ve learned in this tutorial, is Protocol Oriented Programming — see Introducing Protocol Oriented Programming for more details.

Generics in Swift are an integral feature that you’ll use every day to write powerful and type-safe abstractions. Improve your commonly-used code by remembering to ask “Can I genericize this?”