What is SwiftLint? — The trip to the Clean Code

Mammadowr
3 min readJul 29, 2022

I guess you did not read yet my previous articles. Then take a look at them to be able to understand this article better. :)

I want to congratulate you that you read all mentioned articles and you are ready to learn about clean code!

If you are working or worked in a project, you probably used SwiftLint before. In case you did not use, I guess, after reading this article, you are going to use it.

In this article, you will read about:

  1. What is SwiftLint?
  2. How to install it?
  3. How to use it?

Why SwiftLint?

Well, the motto says a lot about itself: Write beautiful code in Swift. It is a tool that enforces Swift style and conventions which is developed by Realm.

This is the logic of SwiftLint: It takes all rules from its .yml file. There are default rules that is applying already which you can use and the good part is that you have an opportunity to create your own rules. You decide how many characters should be in a line. You can decide when it should show you a warning and/or when it should show an error.

SwiftLint is the way to write clean code. In case you are asking “Why should I write a clean code?” — Writing a code is not only thinking and pressing buttons on the keyboard. It is a communication between developers.

How to install?

The installation process is very easy.
You can follow steps here: SwiftLint Github

There are couple of ways to install it. I prefer using the home brew. Open your terminal, and paste following code:

After installing it, go to Xcode -> Select your project -> Select target -> Build Phase -> New Run Script Phase
and add following code:

How to use?

Once you are installed it, you can simply go to your compiler and build your project. If there are issues, it will show you automatically.

As I mentioned, you have the opportunity to use the default settings, or you can create your own. I gave couple of examples above, and here is the another one.

You can exclude some parts of your project, such as pods. If you exclude it, then SwiftLint will not check pods.

Basically that is all from my side. If you like my articles, if you think that they are useful, you can click on “Follow” button and share articles to reach more people. :)

--

--

Mammadowr

I speak 6 human and 5 programming languages. 🥳  iOS Developer. To support me: https://www.buymeacoffee.com/mammadowr8 ☕️