How to fix the "SwiftLint not installed" warning on M1 Macs

So I was setting up an Xcode project the other day, and I added the SwiftLint step to the Build Phases. When I ran the build, I was getting the following warning:

SwiftLint not installed, download from

This warning was strange because I installed the SwiftLint on my machine, and it was working without any issues when I ran it from the Terminal.
As it turns out, on the M1 Macs, the SwiftLint is installed in the /opt/homebrew/bin/, not in /usr/local/bin/ as it used to be. Because of this, the SwiftLint is not added to the PATH and is therefore not available for the Xcode.
To fix this issue, we can manually specify where the SwiftLint is, right in the Build Phase step:

alias swiftlint="/opt/homebrew/bin/swiftlint"

if swiftlint >/dev/null; then
  echo "warning: SwiftLint not installed, download from"

In the script above, we create an alias for the SwiftLint executable, located in the homebrew folder, and later use it to lint the code.

That's it. Now, the warning should be gone, and SwiftLint should verify the code during the build process.


Anything interesting to share? Write a comment.