WWDC Notes

Modern Swift API Design

Show Apple's description.
Every programming language has a set of conventions that people come to expect. Learn about the patterns that are common to Swift API design, with examples from new APIs like SwiftUI, Combine, and RealityKit. Whether you're developing an app as part of a team, or you're publishing a library for others to use, find out how to use new features of Swift to ensure clarity and correct use of your APIs.

The most important goal as an API designer: Clarity at the point of use.

@DynamicMemberLookup

It can be used to expose all the properties of a hidden object as if they belonged to the main object.

@PropertyWrapper

  • Provides similar benefits to the built-in lazy
  • Eliminates boilerplate.
  • Documents semantics at the point of definition.

Property Wrappers can be seen as generic getters and a setters:

We can even pass values to the property initializer:

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.