Generics, Operators, and Nested Types

Swift provides a number of advanced features for building functionality that is flexible but well defined so that it feels like you are extending the language itself. In this chapter, we will examine two of these features: generics and operators. We will also see how nested types allow logical grouping, access control, and namespacing for your constructs.

In this chapter, we will cover the following recipes:

  • Using generics with types
  • Using generics with functions
  • Using generics with protocols
  • Using advanced operators
  • Defining option sets
  • Creating custom operators
  • Nesting types and namespacing

Technical requirements

All the code for this chapter can be found in this book's GitHub repository at https://github.com/PacktPublishing/Swift-Cookbook-Second-Edition/tree/master/Chapter04 ...

Get Swift Cookbook - Second Edition 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.