Installing and Using SwiftLint

Get rid of unreadable habits

Image by Art Lasovsky on Unsplash

Before we start

Who is this guide for?

What is SwiftLint for?

The installation

Basic usage: The command line

let array: NSArray = NSArray(array: [5, 6, 7])let numbers = array as! [Int]print(numbers.reduce(0, +))
SwiftLint
Force Cast Violation: Force casts should be avoided. (force_cast)
ViewController.swift:14:29
swiftlint autocorrect

Basic usage: Xcode

if which swiftlint >/dev/null; thenswiftlintelseecho "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"fi
let array: NSArray = NSArray(array: [5, 6, 7])let numbers = array as? [Int]print(numbers?.reduce(0, +) as Any)

Disabling warnings

// swiftlint:disable:next unused_optional_binding
// swiftlint:disable line_length
// swiftlint:disable:next line_length
// swiftlint:disable:this line_length
// swiftlint:disable:previous line_length

Disable Pods Warnings and Errors

excluded:- Pods

Conclusion

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store