Swift-Format
Build phase
Add a script phase Swift format
# Runs the swift formatter build in Xcode executable using swift runtime.
# To format it accordingly
echo "swift format rules applying across the project source files"
swift-format format -i -p --recursive "$SOURCE_ROOT"
Run script:
Based on Dependency analysis
- true but because of xcode yelling me a warning
use discovered dependency file
- none
Integration
Works great with swift_lint as the next step after first formatting your input files.
This eliminates git pre commit hook as well.
No need for CI runner to run things and start commenting on the PRs or even have co-pilot or anything else to run some static analysis on swift code around formatting and linting.
Rules
.swift-format in your root project
{
"indentation" : {
"spaces" : 4
}
}
Dependency Analysis
medium | xcode build output files
Reference
https://troz.net/post/2024/swift_format/