Member-only story
Stride in Swift
Moving through, without a boring For loop
2 min readDec 2, 2019
I’ve spent some time solving Leetcode problems. More technically I’ve had a few issues with 54. Spiral Matrix and 59. Spiral Matrix II and now I find that solutions would have been much easier had I used Stride.
Prerequisites:
- None, a basic knowledge of programming in Swift would be helpful
Terminology
Sequentially: A logical order or sequence
Stride: A function to stride over values of any type
The problem
Imagine you want to move through an array.
The traditional way is to use a for loop. An alternative is to use stride, and that produces the same result.
The syntax is rather different, but at first glance you can pick one or the other and be relatively pleased with either choice.
This article is about choosing Stride in Swift. Why?