gitmyhub

swift-style-guide

★ 13k updated 1y ago

The official Swift style guide for Kodeco.

Official Swift coding style guide from Kodeco covering naming, formatting, and code organization rules so all contributors write consistent, readable Swift code.

SwiftSwiftLintsetup: easycomplexity 1/5

This repository holds the official Swift style guide for Kodeco, a platform known for producing programming books and tutorials. Swift is the language used to build apps for Apple devices like iPhone and Mac. A style guide is a set of agreed-upon rules for how code should be written, covering things like naming variables and functions, organizing files, and formatting whitespace. This particular guide was created so that the many different authors contributing to Kodeco books and tutorials would all write code in a consistent way.

The stated priorities are clarity first, then consistency, then brevity. The guide leans heavily on official Swift conventions published by Apple, and it also requires or strongly encourages the use of a tool called SwiftLint, which can automatically flag code that breaks the rules.

The guide covers a wide range of topics in detail. On naming, it provides rules for how to name variables, types, functions, delegates, and generic parameters, along with conventions for how to refer to methods when writing about them in text. On code organization, it recommends grouping related functionality using extensions and marking those sections with standard comments. It also covers spacing around braces and operators, when to write comments and when not to, how to structure classes versus structures, how to write function declarations and closure expressions, how to handle optional values (places where something might be absent), and how to manage memory safely.

Additional sections address access control (deciding what parts of code are visible outside a file or module), control flow patterns, when to use guard statements, and smaller conventions like avoiding semicolons and emoji. The guide also includes rules about copyright statements and project bundle identifiers.

Because the guide runs to over 38,000 characters, only a portion of it is captured here. The full README is longer than what was shown.

Where it fits