0

Sometimes I need to use for loop that iterates from end of array. Since Swift 2.2 Xcode says that it is deprecated and I cannot find any way to write it now.

Example:

for var i = (tableData.count - 1); i >= 0; i-- {

}

I know that standard for loop can be rewritten like this:

for i in 0 ..< blocks.count {

}

Is there anyway to make it work?

Tomáš Chylý
  • 342
  • 1
  • 8
  • 21

1 Answers1

2

Use the reverse() function

for i in (0 ..< tableData.count).reverse() { }
vadian
  • 274,689
  • 30
  • 353
  • 361