# github/swift-style-guide

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/github-swift-style-guide).**

4,762 stars · 560 forks · CC0-1.0 · archived

## Links

- GitHub: https://github.com/github/swift-style-guide
- awesome-repositories: https://awesome-repositories.com/repository/github-swift-style-guide.md

## Description

This project is a set of coding standards, architectural patterns, and type safety guidelines for writing Swift source code. It provides a framework for maintaining clean and maintainable code through established conventions and formatting rules.

The guide prioritizes composition over class inheritance by favoring value types and final classes. It establishes a policy for access control to manage boundaries between internal logic and external components through explicit visibility modifiers.

The standards cover type safety optimization through immutable bindings and safe optional handling. Additional areas include the use of early exit patterns to optimize logic flow, the reduction of syntax verbosity, and the application of uniform code formatting.

## Tags

### Development Tools & Productivity

- [Swift Linting Standards](https://awesome-repositories.com/f/development-tools-productivity/swift-linting-standards.md) — Establishes a comprehensive set of rule sets and standards to enforce consistent syntax and style in Swift.
- [Code Style Standardization](https://awesome-repositories.com/f/development-tools-productivity/code-style-standardization.md) — Provides guidelines for maintaining consistent whitespace, indentation, and visual structure across the codebase. ([source](https://github.com/github/swift-style-guide#readme))

### Programming Languages & Runtimes

- [Immutable Variables](https://awesome-repositories.com/f/programming-languages-runtimes/immutable-variables.md) — Prioritizes the use of constants over variables to prevent accidental state mutation and improve thread safety.
- [Type Safety](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety/end-to-end/type-safety.md) — Improves overall type safety by mandating constants and explicit optional handling. ([source](https://github.com/github/swift-style-guide/blob/master/README.md))
- [Swift Type Safety Patterns](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety/end-to-end/type-safety/swift-type-safety-patterns.md) — Provides guidelines for implementing immutable bindings and safe optional handling to prevent runtime crashes.

### Software Engineering & Architecture

- [Architectural Governance](https://awesome-repositories.com/f/software-engineering-architecture/architectural-governance.md) — Provides a framework for enforcing project-wide architectural constraints and design goals within Swift projects.
- [Protocol-Oriented Design](https://awesome-repositories.com/f/software-engineering-architecture/integration-extensibility/dependency-injection/protocol-oriented-injection/protocol-oriented-design.md) — Promotes protocol-oriented design and protocol composition to reduce coupling and complexity.
- [Value Unwrapping](https://awesome-repositories.com/f/software-engineering-architecture/optional-value-types/value-unwrapping.md) — Standardizes explicit unwrapping techniques for optional types to eliminate runtime crashes.
- [Layer Visibility Enforcement](https://awesome-repositories.com/f/software-engineering-architecture/project-management-governance/dependency-boundary-enforcers/module-boundary-enforcement/layer-visibility-enforcement.md) — Maintains strict boundaries between architectural layers through the application of visibility modifiers. ([source](https://github.com/github/swift-style-guide/blob/master/README.md))
- [Composition Over Inheritance](https://awesome-repositories.com/f/software-engineering-architecture/software-architecture/architectural-patterns/modular-decoupled-design/structural-design-paradigms/composition-over-inheritance.md) — Provides standards for favoring composition and protocol-oriented design over deep class inheritance hierarchies.
- [Swift Access Control Standards](https://awesome-repositories.com/f/software-engineering-architecture/swift-access-control-standards.md) — Defines the application of explicit visibility modifiers to protect internal logic in Swift.
- [Swift Architectural Guidelines](https://awesome-repositories.com/f/software-engineering-architecture/swift-architectural-guidelines.md) — Sets standards for prioritizing value types and composition over complex class inheritance hierarchies.
- [Value Type Prioritization](https://awesome-repositories.com/f/software-engineering-architecture/value-type-prioritization.md) — Favors structs and enums over classes to ensure predictable state and reduce memory overhead.
- [Explicit Modifier Requirements](https://awesome-repositories.com/f/software-engineering-architecture/visibility-modifiers/explicit-modifier-requirements.md) — Enforces explicit visibility modifiers on top-level definitions to protect internal implementation details.
- [Explicit Visibility Enforcement](https://awesome-repositories.com/f/software-engineering-architecture/visibility-modifiers/implicit-modifier-explicitly/explicit-visibility-enforcement.md) — Hides internal logic from external components by applying explicit access control specifiers. ([source](https://github.com/github/swift-style-guide#readme))
- [Access Control Policies](https://awesome-repositories.com/f/software-engineering-architecture/access-control-policies.md) — Defines policies for applying explicit visibility modifiers to isolate internal implementation details from public APIs.
- [Architectural Preference Standards](https://awesome-repositories.com/f/software-engineering-architecture/architectural-preference-standards.md) — Provides architectural standards for choosing between value and reference types to simplify maintenance. ([source](https://github.com/github/swift-style-guide#readme))
- [Code Readability Optimizations](https://awesome-repositories.com/f/software-engineering-architecture/code-readability-optimizations.md) — Implements techniques to improve code readability through patterns like early exits and concise property declarations.
- [Early Return Patterns](https://awesome-repositories.com/f/software-engineering-architecture/code-readability-optimizations/early-return-patterns.md) — Standardizes logic flows by using early returns to align the happy path and improve readability.
- [Early-Return Patterns](https://awesome-repositories.com/f/software-engineering-architecture/control-flow-optimization/early-return-patterns.md) — Implements early-return patterns using guard statements to reduce nesting and handle edge cases efficiently.
- [Swift API Design Guidelines](https://awesome-repositories.com/f/software-engineering-architecture/swift-api-design-guidelines.md) — Offers design guidelines for creating robust and type-safe APIs in Swift.
- [General](https://awesome-repositories.com/f/software-engineering-architecture/type-safety-patterns/general.md) — Applies safety patterns including immutable bindings and safe optional handling to prevent crashes. ([source](https://github.com/github/swift-style-guide#readme))

### Part of an Awesome List

- [Programming Language Standards](https://awesome-repositories.com/f/awesome-lists/devtools/programming-language-standards.md) — Official Swift style and conventions.
- [Coding Standards](https://awesome-repositories.com/f/awesome-lists/learning/coding-standards.md) — Swift coding style and habits guide.
