Search code examples
swiftswiftlint

Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)


I am currently using SwiftLint for the perfect coding standards in my projects. After installing it I am getting so many warnings and the common ones are:

"Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon)".

enter image description here

var indexPath:IndexPath!
static let collapsedHeigth : CGFloat = 80
static let expandedHeigth : CGFloat = 210

What does it means and how to improve it?


Solution

  • The warning is telling you that your code should be:

    static let collapsedHeigth: CGFloat = 80
    static let expandedHeigth: CGFloat = 210
    

    The colon should not have whitespace before it when declaring variables or when creating key-value pairs in a dictionary.

    let someDictionary = [ "Hello": 4, "Bye": 42 ]
    

    BTW - you can solve the "trailing whitespace" errors with a simple setting in Xcode preferences. Go to the Text Editing tab of the preferences and enable the "Automatically trim trailing whitespace" option.