SwiftLint, SwiftFormat 설치
$ brew install swiftlint
$ brew install swiftformat
Build Phase Script Phase 추가
Build Phase: 타겟을 빌드하기 위해 필요한 파일들을 단계별로 어떻게 처리할지 구성한 목록
Target 프로젝트 > Build Phase > + > New Run Script Phase 클릭

SwiftLint Script 설정 (Apple Silicon 기준) / swiftformat.yml Rules.md
Run Script Phase의 이름을 SwiftLint 로 설정
# Type a script or drag a script file from your workspace to insert its path.
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint > /dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

SwiftFormat Script 설정 (Apple Silicon 기준) / swiftformat.yml Rules.md
Run Script Phase의 이름을 SwiftFormat 으로 설정
# Type a script or drag a script file from your workspace to insert its path.
export PATH="$PATH:/opt/homebrew/bin"
if which swiftformat > /dev/null; then
swiftformat .
else
echo "warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat"
fi

Build Phase 목록 정렬

코드 빌드 (command+R)
![]() | ![]() |
|---|
기본설정에 더해 프로젝트 상황에 맞게 추가적으로 룰을 설정 가능
line_length: 150
identifier_name:
excluded:
- i
- n
- x
- y
👉 SwiftLint-line_length
👉 SwiftLint-identifier_name
Build Settings User Script Sandboxing 설정
Failed to read contents of directory at 과 같은 오류가 뜬다면 아래 처럼 No 로 설정

Xcode Indent 설정
Xcode > Settings > Text Editing > Indentation

.swiftlint.yml
opt_in_rules:
- indentation_width
...
indentation_width:
- indentation_width: 2
코드 정렬
Ctrol + i > Command + R
Reference
SwiftLint와 SwiftFormat 적용하기
Xcode custom script 시작하기
[Xcode] Project editor - 프로젝트 편집기
[iOS] SwiftLint 적용하기 + 에러해결
[Xcode] 들여쓰기(Indentation) 탭 스페이싱 조절