add SwiftLint to Xcode workspace

Asked on 2024-07-30

1 search

To add SwiftLint to your Xcode workspace, you can follow these general steps:

  1. Install SwiftLint: You can install SwiftLint using Homebrew by running the following command in your terminal:

    brew install swiftlint
    
  2. Add a Run Script Phase: In your Xcode project, navigate to your target's build phases and add a new "Run Script Phase". You can do this by clicking the "+" button in the top left corner of the build phases tab.

  3. Configure the Run Script: In the new run script phase, add the following script to run SwiftLint:

    if which swiftlint >/dev/null; then
        swiftlint
    else
        echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
    fi
    
  4. Customize SwiftLint: Optionally, you can customize SwiftLint by creating a .swiftlint.yml file in the root of your project. This file allows you to configure rules, exclude files, and more.

For more detailed information on custom scripts in Xcode, you can refer to the session Extend your Xcode Cloud workflows at WWDC 2024, which discusses how to define custom scripts inside your repository that will be run at specific points in your build process.

Relevant Sessions