O'Reilly logo

Swift 3 Functional Programming by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Generics and Associated Type Protocols

Generics enable us to write flexible reusable functions, methods, and types that can work with any type. This chapter explains how to define and use generics and introduces the problems that can be solved with generics in the Swift programming language with examples.

This chapter will cover the following topics with coding examples:

  • Generic functions and methods
  • Generic parameters
  • Generic type constraints and where clauses
  • Generic data structures
  • Associated type protocols
  • Extending generic types
  • Subclassing generic classes

What are generics and what kind of problems do they solve?

Swift is a type-safe language. Whenever we work with types, we need to specify them. For instance, a function can have specific ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required