How to create a SwiftLint enabled Swift Xcode Project

A step by step tutorial on creating an iOS Xcode project with SwiftLint. Github repository included.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 07/11/2022 at 16:04
Last Updated on 06/16/2023 at 14:50
A flower that represents Swift next to a Flower that represents Xcode with the text 'SwiftLint Xcode Starter Project' below it.

A step by step tutorial on creating an iOS Xcode project with SwiftLint. Github repository included.

The following step by step tutorial walks you through how to create a SwiftLint enabled Xcode project.

If you are looking for the specific SwiftLint part jump to step six.

Download open source projectHow to create a structured XCode project

Step One: Open Xcode

Xcode by Apple

Using Spotlight or Finder, Open Xcode.

Download Xcode

Step Two: Create a new Xcode project

In the modal that appears, select create new Xcode project.

In the window that appears, select Create a new Xcode project.

Step Three: Select iOS App

Select App, under the iOS tab in the menu and press next.

In the pop up that appears, select App under iOS and press Next.

Step Four: Name your project

An image of the modal that appears informing you how to name the project, set the storyboard as the interface as well as how to set the swift language. Finally, we highlighted where to press next.

Next to product name, name your project. In our case we called it Starter Project.

Please note that we use a Storyboard Interface and the Swift Language.

Once ready press Next.

Step Five: Save your project

A screenshot of finder showing you what the save screen looks like for an Xcode project on creation.

In your chosen destination, save your project.

Step Six: Install SwiftLint

A screenshot of terminal telling you to run 'brew install SwiftLint' - the line required to install SwiftLint on a Mac.

Open Terminal and run the following command

brew install SwiftLint

Please note this step assumes that you have HomeBrew installed.

Install HomeBrew

Step Seven: Navigate to Build Phases

A screenshot showing you how to navigate to 'Build Phases' on your Xcode project.

Go back to your project and select Build Phases.

If it is not visible, Select Starter Project with the App Logo from the file inspector, then under Targets select Starter Project and then Build Phases.

Step Eight: Add a new build phase

A screenshot showing you where the '+' is found to add new build phases. Its on the top left under general.

Select '+' under General.

Step Nine: Add a new run script phase

A screenshot showing you the modal that appears, and where to select 'New Run Script Phase'.

From the pop up that appears, select New Run Script Phase.

Step Ten: Open the Run Script tab

A screenshot showing you how to open the 'Run Script' tab under the build phases.

Press the caret next to Run Script to open up the tab.

Step Eleven: Paste in the SwiftLint with autocorrect & format

Our chosen Run Script code.

Under the shell area, paste in the code below. This code will autocorrect and format your swift project on build.

Please note that you must uncomment line 2 for it to work on Apple Silicon.

Stackoverflow | Swiftlint can't be found on Apple Silicon xcode

Step Twelve: Create your swiftlint.yml

A screenshot of our created swiftlt.yml - we created it based on a swift file and renamed it on save.

Create your SwiftLint yaml file under your Starter Project Folder - we created a swift file and on save, named it .swiftlint.yml.

Step Thirteen: Input your configuration

A screenshot of our YAML code

This is the file that dictates your SwiftLint strategy. Ours includes indentation width, explicit self and operater usage whitespace.

For a full list, please visit the SwiftLint repository in the button below.

View available SwiftLint Configurations

Verify by making changes and running a build

You should see your project auto update to reflect changes upon building.

Please note that it may not automatically lint your open file every time and you might want to select a separate file when building.

Download open source project

Looking to implement SwiftLint in a pre-commit githook ?

To learn how to implement SwiftLint in a pre-commit githook that's added to the repository on build, carry out the tutorial linked below.

How to add a pre-commit githook script during the build phase in XCode

Looking for more XCode tutorials ?

Search our blog to discover our 100+ iOS, Xcode and Apple related content.

Search our Blog

Any questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.

SubscribeInquireView All PostsView All ServicesView All Posts

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe