Connect with us

Articles

Improving Swift Code Readability With SwiftLint

SwiftLint is a swift code style analysis tool that helps you flag stylistic errors in your code. It can help you enforce these styles by marking build as failures or with warnings when the style is not followed.

Read more by Anurag Ajwani @ Better Programming

Should we use shorthand argument names in closures? Or should we declare the argument list in the closure declaration?

let evenNumbers = [0, 1, 2, 3, 4, 5, 6].filter { $0 % 2 == 0 }

or

let evenNumbers = [0, 1, 2, 3, 4, 5, 6].filter { number in
    number % 2 == 0
}

Discussions like these are common amongst iOS developers working on a common project. Having different styles to write code can create confusion and make code harder to read. It is common for developers to follow and adhere to a set code style guidelines in an attempt to maintain consistent code styling. Raywenderlich’s swift code style guide is one of the most popular ones.

However there can be many rules. When reviewing each others code it can be hard to remember all of these rules. So is there a better way to check and warn when the guidelines are not being followed? Yes of course there is!

SwiftLint is a swift code style analysis tool that helps you flag stylistic errors in your code. It can help you enforce these styles by marking build as failures or with warnings when the style is not followed.

In this tutorial I will show you how to setup SwiftLint, configure it and use it within Xcode build process.

I assume you are already fairly comfortable around developing iOS applications and with Swift.

Advertisement

Trending