Swift Lint & Apple Silicon Computers
What is Apple Silicon?
Starting with certain models introduced in the late 2020, Apple began the transition from Intel processors to Apple silicon in Mac computers.
Check out the instructions here by Apple to check what Apple computer you are using: https://support.apple.com/en-in/HT211814
What is Swift Lint?
GitHub Swift Style GuideRay Wenderlich’s Swift Style Guide
To know how to install SwiftLint in your Apple computer follow the instructions here: https://github.com/realm/SwiftLint
I recently transitioned from using an older Macbook to the new Macbook M1 Pro. The code I was working on has Swift Lint enabled in it at its glory! After completing the cloning, and installing the swift lint using the “Homebrew” the issue started popping up.
https://github.com/realm/SwiftLint
This is the message we have added to the run script phase on our project. This script checks for the swift lint file program installed in our machine and tries to access it. If it was not found on the expected location it will throw the above warning. This is strange, I just installed swift lint just as it was explained in its setup guide.
What is the reason?
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.
The Solution
From the official documentation found in Swift Lint’s github page, we can find the solution for this problem.
add /opt/homebrew/bin to the PATH environment variable in your build phase
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint > /dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
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.
Thats all Folks!
References:
- GitHub - realm/SwiftLint: A tool to enforce Swift style and conventions.
- How to fix the "SwiftLint not installed" warning on M1 Macs | This Dev Brain by Michal Tynior
Author Notes
This article is an attempt to increase the sources available for solving some particular problem.
If you are interested in my writing style, and would want to read more articles, comment your interested topics on the response section.