Ahil
Ahil

Reputation: 67

Control Statement Violation inside for-loop

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)
        }

    }

Upvotes: 4

Views: 8468

Answers (2)

Abu Ul Hassan
Abu Ul Hassan

Reputation: 1396

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)
        }

    }

Upvotes: 6

Toseef Khilji
Toseef Khilji

Reputation: 17409

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.

Upvotes: 3

Related Questions