Jordan Jordan - 1 year ago 205
iOS Question

C-style for statement has been removed in Swift 3 (Continuos error)

I have had this problem since updating to

Swift 3
. I have tried updating this to
Swift 3
by using
but I can't implement the old
Swift 2
code to the
Swift 3
code. Below I have included my code:

for var i = 0; i <= self.senderArray.count - 1; i += 1 {

if self.senderArray[i] == userName {

else {




The error I am getting:

C-style for statement has been removed in Swift 3

I have tried this method below, but it doesn't work:

for i in 0 ..< self.senderArray.count

Before anyone marks this question as a duplicate I have had a look at the following questions but for some reason, I can't figure out how to implement my code into the updated
Swift 3

#warning: C-style for statement is deprecated and will be removed in a future version of Swift

How to fix C-style for statement?

Fix warning "C-style for Statement is deprecated" in Swift 3

Fix "C-style for statement is deprecated" in Swift

Answer Source

Keeping the index is easy with enumerated:

for (i, sender) in senderArray.enumerated() {
    // Can simply use 'sender' here, no need to index into senderArray.
    if sender == userName {

    // Unchanged lines; 'i' is used as index here.   

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download