WWDC Notes

Swift Generics (Expanded)

Show Apple's description.
Generics are one of the most powerful features of Swift, enabling you to write flexible, reusable components while maintaining static type information. Learn about the design of Swift's generics, including how to generalize protocols, leverage protocol inheritance to express the varying capabilities of related types, build composable generic components with conditional conformances, and reason about the interaction between class inheritance and generics. This expanded version of the WWDC 2018 session includes a brand-new discussion of recursive constraints.
  • Very nice presentation of what Swift Generics are, why they’re better than just defining something as Any (both from code, memory, and compiler perspective)
  • How to create extensions only to some subsets of Generics (see the where ...)
  • How to add constraints to Generics typealias:
  • How to use Generics in protocols (via associatedtype)
    • You can add constraints on the associatedtype:
    • Protocol Inheritance

Missing anything? Corrections? Contributions are welcome 😃

Related

Written by

zntfdr

Federico Zanetello

Federico Zanetello is an iOS Engineer with strong passion for Swift, minimalism, and design. When he’s not busy automating things, he can be found writing at fivestars.blog and/or playing with the latest shiny toys.