How to become a better developer? — Watch your language!
Swift-lint your new grammar teacher 👨🏫
When i was in the university i had a teacher who tell me that the difference between a good dev and bad one is just some details… Of course, just the details but who will show us these details? — Don’t look at me, there is no silver bullet for that, you have to work a lot if you want to be a good dev, this is just like be a good writer, how will you improve your language? you are right, writing. What i’m triying to say is that if you want to become an expert in something you have to doing a lot.
I think that the picture that u/Not_BruceWayne post in reddit explain very well what i’m trying to tell you.

Well after my motivational speech i want to show you today a tool to become a better writter, sometimes we don’t know how to write good code or even maintainable, and in the university it seems that no one has the answers, (at least in my time in the university was like that 😅).
Fortunately now we can find a good teachers in youtube and a lot of advices and tools like the one today i’ll exlplain you how to use.
Swift-lint
In the word of their creators swiflint is a tool to enforce Swift style and conventions, loosely based on GitHub’s Swift Style Guide. You can think in lint as a you grammar teacher which won’t let you compile your project unless you don’t have serios mistakes, and also will let you know all your grammar problems with nice warning along all your project.
In the following link you can find the pod for lint.
I really encourage you to read the documentation because this is a very extensive tool, but if you want to choose the easy way keep reading:
- Add the pod: In your podfile just add the following line
pod 'SwiftLint' - Install the pod: Run the command to install it
${your-project-path}/pod install - Then you have to add a new script to run lint in your project. In your xcode project go to the main target and then in the
Build Phasestab

4. Create a new script, just like the following gif

There is some points that you need to check in this part, first is that I’m rename it the script to Swiftlint this is only for organizationals purposes, then move it to the second position, it’s important that this script will be in the second position, just after the Target Dependencies one, this is because we don’t want to continue the process if we have some lint errors and warnings if you are perfectionist guy (like me 😅). Once this is in the correct positions you have to add the following bash command "${PODS_ROOT}/SwiftLint/swiftlint" this is just running the executable for lint in the current path which is installed, in this case in the Pods directory under the SwiftLint folder.
5. We are almost done, in my case i don’t want that lint evaluate all the code for the pods that i installed in my project, i’ll only take care for my code so i’ll create a .swiftlint.yml file to specify this.

That it! now you have lint installed and running, now you only have to hit the build button and you’ll see all the problems errors and worning that you have know… something like this.

The most common errors for lint in my project was the force_cast violation and the most common warning was the trailing_whitespace the first one i think is very clear but the second one are just an special caracter that xcode adds for every blank spaces in your code. This sounds like will be a pain in the ass to try to delete it…. but wait a minute, swiftlint autocorrect to the rescue.

Just before to show you this magic command let’s take a look at all the rules that lint is evaluating. if you run the following command ./Pods/SwiftLint/swiftlint rules in the root directory you will see the following:

As you can see there is a column named correctable this means that swift lint can autocorrect that mistake for us, like the annoying special caracter for xcode and a buch of more rules. in order to auto correct your project you have to run the following command ./Pods/SwiftLint/swiftlint autocorrect and you’ll see something like this:

Now after running that command, you will see that your warning and errors are less than before.

Now it’s time to get the hands dirty and fix all the warnings and the errors, i guess that all the rules are pretty clever but if you need some clarification you can google some of them if you are not pretty sure how to fix it.
Finally just as we did to ignore some folders we can enable, disable or even modify some rules using our configuration file .swiftlint.yml but i strongly recommend you, don’t do it. All the rules by default all the ones for the Github convention and unless you have strongly fundaments to change it, i’ll recommend to don’t do it.
I encourage you to try to follow all of them, the results will be awesome, your code will be more readable sustainable and now all that changes in producctions won’t be a nightmare 👊
