Swift Style Guide

Airbnb's Swift Style Guide
By Francisco Diaz

Why a Swift Style Guide?

Swift is a young language. When we started using it back in 2014, we had no standardized Swift style guidelines. We let 15 engineers loose in our codebase, each of them writing with their own personal Swift style. It quickly became clear that if we didn’t agree on a standardized style, we’d either spend too much time discussing style in our PRs, or our codebase would resemble a Jackson Pollock painting.

When we were working on our Apple TV app, we started an informal style guide. In January 2016 this was combined with other ad-hoc efforts to become the official Airbnb Swift Style Guide, where we started collaborating to define what was the preferred way to write Swift at Airbnb.

Apple and the Swift community have provided valuable guidance on how to write Swift. Even though they absolutely influenced how we write Swift at Airbnb, we still see value in keeping our own Style Guide as a way to iterate on what feels correct to us, while at the same time keeping in line with the community. That’s why we added Apple’s recommendations to our guiding tenets.

We don’t want to manually identify and correct style guide violations, so we’ve adopted the most popular linter and formatter in the Swift community, SwiftLint and SwiftFormat, respectively. In our Style Guide you’ll find our SwiftLint and our SwiftFormat configurations. If you want to use the same rules as us, just grab them and start using it in your projects!