Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

    }
like image 376
Ahil Avatar asked Oct 18 '25 15:10

Ahil


2 Answers

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

    }
like image 52
Abu Ul Hassan Avatar answered Oct 20 '25 07:10

Abu Ul Hassan


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.

like image 43
Toseef Khilji Avatar answered Oct 20 '25 07:10

Toseef Khilji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!