SW

Swift Defaults

Core Swift coding conventions

Details

Language / Topic
swiftSwift
Category
Style Guide

Rules

balanced
- Follow Swift API Design Guidelines: clear, expressive names that read as grammatical phrases.
- Use `let` for constants by default; `var` only when mutation is needed.
- Use `guard let` for early returns and `if let` for optional binding — `guard` improves readability by reducing nesting.
- Use Swift's value types (`struct`, `enum`) by default — use `class` only when reference semantics or inheritance is needed.
- Use optionals correctly: prefer `guard let` for early exit, `if let` for conditional binding.
- Use `Result<Success, Failure>` for operations that can fail. Use `throws` for propagation.
- Mark types and methods with appropriate access control (`private`, `internal`, `public`).
- Use Swift concurrency (`async`/`await`, `Task`, `Actor`) for concurrent operations.