The swiftlint project says that you can do this with the following steps:
Xcode
Integrate SwiftLint into your Xcode project to get warnings and errors displayed in the issue navigator.
To do this click the Project in the file navigator, then click the primary app target, and go to Build Phases. Click the + and select "New Run Script Phase". Insert the following as the script:
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
You might want to move your SwiftLint phase directly before 'Compile Sources' step, to detect errors quickly before compiling. However, SwiftLint is designed to run on valid Swift code that cleanly completes the compiler's parsing stage. So running SwiftLint before 'Compile Sources' might yield some incorrect results.
If you wish to autocorrect violations as well, your script could run swiftlint autocorrect && swiftlint instead of just swiftlint. This will mean that all correctable violations are fixed, while ensuring warnings show up in your project for remaining violations.
If you've installed SwiftLint via CocoaPods the script should look like this:
"${PODS_ROOT}/SwiftLint/swiftlint"
I think using swiftlint like this is recommended. The only warning is
You might want to move your SwiftLint phase directly before 'Compile Sources' step, to detect errors quickly before compiling. However, SwiftLint is designed to run on valid Swift code that cleanly completes the compiler's parsing stage. So running SwiftLint before 'Compile Sources' might yield some incorrect results.
which is about the placement of the script and not the script itself. This says that swiftlint is only guaranteed to perform correctly on valid source code, so you are only guaranteed that swiftlint will work correctly if you place the script after the 'Compile Sources' phase so that swiftlint only runs once the compiler has verified your code.
However, in my personal setup, I use vim to run swiftlint when I save files (generally in an uncompilable state) which runs before compiling, and I have experienced no issues other than the occasional strange formatting when I haven't yet closed all of the { which I have opened. I do not think you will have any issues running swiftlint before the 'Compile Sources' phase.
Note: the other warning on the page
⚠️This plugin will not work with Xcode 8 or later without disabling SIP. This is not recommended.
is not about the 'Run Script Phase'. This is referring to an Xcode plugin which will run swiftlint on save like is possible with vim. To use this plugin on recent versions of Xcode, you need to disable the security feature SIP, which is not recommended. But again, this is unrelated to the 'Run Script Phase' solution.