Tag Archives: SwiftLint

How to add the SwiftLint without pain

Why do you need SwiftLint?

  1. It speed ups code reviews, you stop wasting time on code formatting, force casting, and other common issues
  2. It improves the code quality, code becomes more readable, and maintainable


1. Add SwiftLint to a podfile

Or use another option from the official documentation.

2. Add this .swiftlint.yml config file to the project root folder

The main trick to make integration easy is to disable all rules at first.

3. Build a project, add additional rules to the disabled_rules section, if there are many warnings for them

4. Delete rules from the disabled_rules section one by one and fix all the warnings

5. Leave the trailing_whitespace and other rules that you don’t want to fix in the disabled_rules section

In the end, you will have something like this in your config file.

Some ideas on how to fix common code issues

Force Cast Violation: Force casts should be avoided. (force_cast)



Force Try Violation: Force tries should be avoided. (force_try)




In very rare cases you will not be able to fix the warning. For example, when you use a framework and you cannot easily change its API. Then you can switch off a SwiftLint rule for a particular code block using // swiftlint:disable rule_name and // swiftlint:enable rule_name comments.