Skip to content

Swift Style Guides

Cyndi Chin edited this page Jul 19, 2024 · 13 revisions

This page is a work in progress. Many of the style rules we follow are covered by Swiftlint and we are working on adding more.

Some rules we've worked out we all like:

  • Selectors: #selector(ClassName.methodName) is clearer than #selector(methodName).
  • Type inference: .white is better than UIColor.white.
  • Only use self if required.
  • Always use an explicit return. As a team, we voted against enabling implicit_return for swiftlint.
  • Use final for classes that are not designed to be subclassed. This allows for compiler optimizations and clarifies the intent regarding the class's use and inheritance. It's a good practice to default to final and only remove it when you explicitly need subclassing. More on this here.
  • When creating font types for our UI elements, use FXFontStyles to specify the font instead of calling directly DefaultDynamicFontHelper.
Clone this wiki locally