Swiftlint can't be found on Apple Silicon xcode
Asked Answered
T

5

45

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.

Taster answered 1/2, 2021 at 11:1 Comment(1)
Did you figure this out? I have the same issue.Villeneuve
C
94

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
Cladding answered 2/2, 2021 at 4:21 Comment(1)
"The swiftlint autocorrect command is no longer available. Please use swiftlint --fix instead." (swiftlint version 0.47.1)Shamekashameless
M
16

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

Meitner answered 19/4, 2022 at 14:32 Comment(1)
While this works, I would recommend against this approach. Funky symlinks on your local system cannot be checked in to source-control, and are a manual step which are prone to breaking from system to system.Anastase
B
1
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
Bysshe answered 27/9, 2022 at 7:37 Comment(1)
all the things I tried this is only one that worked now with a new swiftLint install on a Mac mini m1 on latest Mac OS Sonoma 14.2 with brew --version Homebrew 4.1.25 with swiftlint --version 0.53.0 and in late 2023Scupper
C
0

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.     
Cymry answered 11/9, 2023 at 9:8 Comment(0)
V
0

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
Vulnerary answered 27/5 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.