SwiftLint on Apple Silicon M1

If you want to install SwiftLint, you can do so by running the following command in your terminal:

brew install swiftlint

Once you’ve installed SwiftLint, you can check where it’s located on your system by running:

which swiftlint
// For Apple Silicon -> /opt/homebrew/bin/swiftlint

If you’re using an Apple Silicon chip, SwiftLint may be located in the /opt/homebrew/bin directory. To ensure that SwiftLint is available in your build phases, you’ll need to add the following script to your Run Script phase:

# Build Phases -> Run script phase for Apple Silicon chips
# Adds support for Apple Silicon brew directory
export PATH="$PATH:/opt/homebrew/bin"

if which swiftlint; then
    swiftlint autocorrect && swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

This script adds support for the Apple Silicon brew directory and checks if SwiftLint is installed. If SwiftLint is installed, it will autocorrect and run it. Otherwise, it will display a warning message and provide a link to download SwiftLint from GitHub.

For those who wish to bypass the autocorrect function, simply replace swiftlint autocorrect && swiftlint with swiftlint.

If you encounter the error Sandbox: swiftlint(xxxxx) deny(1) file-read-data xxx /.swiftlint, navigate to Build settings and set the User Script Sandboxing value to “No”.

Leave a Comment