3

I am using SwiftLint in my app. I am getting Control Statement Violation: if, for, guard, switch, while, and catch statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses. (control_statement). What is wrong with that code? Why i am getting that waring? Thanks in Advance

   for i in 0..<images.count {

        if(i == images.endIndex - 1) {
            print(i)
        }

    }
Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
Ahil
  • 57
  • 2
  • 11

2 Answers2

6

Its simply telling parentheses start ( and parentheses end ) symbols are now not necessary to provide in control statement' conditions so your code will go without () in control statement conditions for example your code will look like below

 for i in 0..<images.count {

        if i == images.endIndex - 1 {
            print(i)
        }

    }
Abu Ul Hassan
  • 1,340
  • 11
  • 28
3

You have added parentheses in if condition. Remove it.

for i in 0..<images.count {

        if i == images.endIndex - 1 {
            print(i)
        }

 }

You can check detail rule here.

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121