Skip to main content

Code Style

Tools

.swiftlint.yml and .swiftformat are the source of truth. When in doubt, check those files.
SwiftLint also runs during Xcode builds automatically.

Formatting

Naming

Access Control

Always explicit. Prefer the most restrictive level that works.

Imports

System frameworks first (alphabetical), then third-party, then local. Blank line after imports.

Safety

No force unwrapping (!) or force casting (as!). Use guard let, if let, as?.

Logging

OSLog only. Never print().

Localization

  • String(localized:) for user-facing strings in computed properties, AppKit code, alerts, error descriptions
  • SwiftUI view literals (Text("Save"), Button("Cancel")) auto-localize
  • Do not localize technical terms: font names, database types, SQL keywords, encoding names
  • Never use String(localized:) with string interpolation. Use String(format: String(localized: "Preview %@"), name) instead.

SwiftUI Patterns

  • @State for local view state
  • @Observable for viewmodels (Swift 5.9+)
  • Property wrapper order: Environment, State, Binding, regular properties
  • Extract large views into subviews

Limits

When approaching these limits, extract into extension files:
MainContentCoordinator.swift
Extensions
MainContentCoordinator+RowOperations.swift
MainContentCoordinator+Pagination.swift
MainContentCoordinator+Filtering.swift
Group by domain logic, not arbitrary line counts.