Freelancing for Pale Blue

Looking for flexible work opportunities that fit your schedule?

Using SwiftLint with XcodeGen

iOS Mar 31, 2023

Recently I was working on a project using Xcodegen and we needed to install SwiftLint to enforce the code style. This is usually a straightforward procedure but since Xcodegen and CI/CD process were involved it got quite tricky.

Since I started using Swift Package Manager I find it hard to go back to CocoaPods for any reason, but unfortunately, SPM wouldn't support it. I found a way to make it work but it wasn't as stable as I thought it would be.

So I decided to insert the swiftlint executable into the project and run it using a build phase script.

The steps

1) Download the latest swiftlint from Github (it's named, unzip it, and place it in your project directory. I prefer to place it in /Scripts/SwiftLint/.

2) Now we need to run swiftlint locally and on CI/CD to make sure that the style code is enforced. So we have to add a script in the build phase to run it using XcodeGen on each build. We will do that by adding the following code snippet in the project.yml (I will assume that you are already familiar with XcodeGen and you already built your project.yml):

      - script: |
          ./Scripts/SwiftLint/swiftlint lint --quiet
        name: Swiftlint

That's it! Run xcodegen and you will notice the script added to the build phase and is ready to run on the next build.

Happy coding!


Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.