https://github.com/realm/SwiftLint
GitHub - realm/SwiftLint: A tool to enforce Swift style and conventions.
A tool to enforce Swift style and conventions. Contribute to realm/SwiftLint development by creating an account on GitHub.
github.com
SwiftLint는 Swift 코드를 일관된 스타일과 규칙을 적용해 주는 라이브러리다.
이를 이번 프로젝트에 한번 적용해 보았다.
처음 설치할 때 나는 brew install swiftlint로 Homebrew를 이용하여 다운 받았었다.
설치 후 적용하기 위해서는 Targets -> Build Phases 로 간다음, Run Script를 Compile Source 다음에 추가하여 아래 코드를 넣어주면 된다.
if command -v swiftlint >/dev/null 2>&1
then
swiftlint
else
echo "warning: `swiftlint` command not found - See https://github.com/realm/SwiftLint#installation for installation instructions."
fi
export PATH="/opt/homebrew/bin:$PATH" 는 Apple Silicon에서 Homebrew를 사용하여 다운했을 시 넣어준다.
나는 M1 맥북이라 해당 코드를 넣어주었다.
또한 Xcode 15.0 이상에서 error: Sandbox: swiftlint(19427) deny(1) file-read-data. 라는 에러가 뜰 텐데 이를 해결하기 위해서는 ENABLE_USER_SCRIPT_SANDBOXING 를 NO로 하면 된다고 한다.
그런 다음 아래와 같이 .swiftlint.yml 파일을 만들어준 뒤 적용을 하였다.
Auto-correct
자동으로 SwiftLint를 적용하기 위해서는 swiftLint --fix 를 이용하면 된다고 한다.
실행 전 반드시 파일 백업을 하라고 한다.
'DEV' 카테고리의 다른 글
[iOS/Swift] CollectionView, TableView 오류발생 (0) | 2025.04.09 |
---|---|
[iOS/Swift] UIStackView(arrangedSubviews: [ ]) (0) | 2025.04.02 |
[iOS/Swift] addTarget()과 Objective-C 셀렉터(#selector) (0) | 2025.03.31 |
[iOS/Swift] UIKit 코드베이스 UIView 분리하기 (Unable to simultaneously satisfy constraints...) (0) | 2025.03.28 |
[iOS/Swift] JSON 파싱, @escaping, Result, Bundle, Completion Handler, Data(contentsof:) 등등 .. (0) | 2025.03.27 |