Is there a way to work with reverse ranges in Swift?
For example:
for i in 5...1 { // do something }
is an infinite loop.
Swift 3, 4+: you can do it like this:
for i in sequence(first: 10, next: {$0 - 1}) { guard i >= 0 else { break } print(i) }
result: 10, 9, 8 ... 0
You can customise it any way you like. For more info read func sequence reference