• Feed
  • Explore
  • Ranking
/
/
    🛠️ Xcode

    [Xcode] SwiftFormat 사용하기

    SwiftxcodeSwiftFormat
    지
    지성
    2025.04.04
    ·
    1 min read

    SwiftFormat 설치

    brew install swiftformat

    SwiftFormat 적용

    1. Xcode 프로젝트 - TARGETS - Build Phases - New Run Script Phase

    2. 추가된 Run Script에 아래 내용을 넣는다

      if [[ "$(uname -m)" == arm64 ]]; then
          export PATH="/opt/homebrew/bin:$PATH"
      fi
      
      if which swiftformat > /dev/null; then
      swiftformat . --swiftversion 5
      else
        echo "warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat"
      fi
    3. (선택) Run Script의 이름을 SwiftFormat으로 변경한다

    4. Based on dependency analysis 체크 해제

    5. Compile Sources 바로 이전으로 순서를 변경한다

    6. 만약 SwiftLint를 사용한다면, 아래 순서로 배치한다

      ...
      > SwiftFormat
      > SwiftLint
      > Compile Sources
      ...






    - 컬렉션 아티클