Swift Tooling Standards
**Priority: P0 (CRITICAL)**
Define SPM Packages
- Package.swift: Define clear targets, products, and dependencies.
- Modularization: Break large projects into local packages for faster builds.
- Versioning: Use semantic versioning (Major.Minor.Patch) for shared packages.
- Compatibility Preflight: Keep four contracts separate — compiler version, Swift language mode (
-swift-version5/6 and strict-concurrency settings), SDK/Xcode version, and deployment targets (per-API availability).swift-tools-versionis not a fifth "manifest-only" knob: in SwiftPM, tools-version 6.0+ makes Swift 6 language mode the default for the package's targets (override withswiftLanguageModesor.swiftLanguageModeper target), so bumping it silently enables full concurrency checking. Xcode targets useSWIFT_VERSIONinstead. Swift 6.4-only syntax needs a 6.4 compiler and matching SDK — see 6.4 gated features.
See implementation examples for Package.swift structure, SwiftLint config, and environment-specific code.
Enforce Code Quality
- SwiftLint: Use for consistent style enforcement. Create
.swiftlint.ymlin project root withdisabled_rulesandopt_in_rulessections. - Compiler Warnings: Treat warnings as errors in CI to maintain code health.
- Documentation: Use triple slashes
///for documentation comments on public APIs (DocC-compatible).
Manage Build Configurations
- Xcconfig: Use external configuration files to manage build settings.
- Environment Flags: Use
#if DEBUGfor development-only code, closed with#endif. - Schemes: Maintain separate schemes for Development, Staging, and Production.
Anti-Patterns
- No API keys in code: Use environment variables or build configs.
- No // swiftlint:disable: Fix underlying issue.
- No manually added frameworks: Use SPM.