When installing swiftlint with homebrew everything installs correctly but when I open xcode I see the message that swiftlint isn't installed. I read this issue & it say's the homebrew installs under this path now /opt/homebrew
with apple silicon & xcode looks for swiftlint in /usr/local
? How can I get xcode to reconige that I have in fact installed swiftlint. Swiftlint is definitely installed, from terminal I can type swiftlint & see all the commands.
I was unable to find how to modify the $PATH variable for Xcode build phase scripts permanently. This script will add the Apple Silicon homebrew path to your scripts PATH for the duration of the run. I’ve tested this on an M1 and Intel Mac and it works for both.
# Adds support for Apple Silicon brew directory
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint; then
swiftlint —-fix && swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
swiftlint autocorrect
command is no longer available. Please use swiftlint --fix
instead." (swiftlint
version 0.47.1) –
Shamekashameless you can also symlink the path
ln -s /opt/homebrew/bin/swiftlint /usr/local/bin/swiftlint
But make sure you have /usr/local/bin folder first
alias swiftlint="/opt/homebrew/bin/swiftlint"
if swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
I had the same issue with my M1 max, and here are the steps for what I did to fix it, Use the below command to install Swiftlint
brew install swiftlint
then run this command
sudo chown -R $(whoami) /usr/local/bin ln -s /opt/homebrew/bin/swiftlint /usr/local/bin/swiftlint
This helps if you are working with a team that still uses Intel ships then you won't have to change the path in the phase script.
====
The other approach but this will change phase script, but still works for both Intel and Silicon ships is
if test -d "/opt/homebrew/bin/"; then
PATH="/opt/homebrew/bin/:${PATH}"
elif test -d "${HOME}/Documents/SwiftLint"; then
PATH="${HOME}/Documents/SwiftLint:${PATH}"
fi
export PATH
if which swiftlint >/dev/null; then
${PODS_ROOT}/SwiftLint/swiftlint --config
${PROJECT_DIR}/.swiftlint.yml
else
echo "warning: SwiftLint not installed, download from
https://github.com/realm/SwiftLint"
fi.
For Apple Silicon based chip, the following bash script is suggested by Swiftlint
if [[ "$(uname -m)" == arm64 ]]
then
export PATH="/opt/homebrew/bin:$PATH"
fi
if command -v swiftlint >/dev/null 2>&1
then
swiftlint
else
echo "warning: `swiftlint` command not found - See https://github.com/realm/SwiftLint#installation for installation instructions."
fi
© 2022 - 2024 — McMap. All rights reserved.