Building Type-Safe APIs in Swift

Episode 1


Eliminating Stringly Typed Code

Swift has a lot to offer, but it isn't always obvious how to get the most out of the language. I often see developers compromise the APIs they build by using stringly typed code while Swift provides features that make stringly typed code unnecessary. In this series, I show you how a handful of simple patterns and techniques can help you build APIs that are type-safe, elegant, and intuitive to use.

Episode 2


Creating Events

In this episode, we focus on the analytics API itself. We define a single entry point for analytics and remove some of the string literals at the call site. The resulting API is surprisingly small, intuitive to use, and easy to extend.

Episode 3


Defining Properties

We still use string literals to define the properties of an event. That is something I would like to change in this episode. The Journey enum defines the list of events the API supports. We take a similar approach for the properties of an event.