Sitemap
Stanley Miller 

Stanley Miller 

iOS Developer. Author. Fan of the interesting. Written 100+ Swift/SwiftUI articles.

Member-only story

Advanced Swift: Stride

Learn about stride in the Swift Programming Language

4 min readFeb 3, 2025

--

Press enter or click to view image in full size

Imagine you’re walking down a staircase, but instead of taking every single step, you decide to take one step, skip two, and repeat. You control the distance between steps. In Swift, stride is your tool for creating controlled, custom steps over a range of values. Whether you’re iterating through numbers, creating animations, or building charts, stride gives you flexibility and precision.

What Is stride?

The stride(from:to:by:) and stride(from:through:by:) functions in Swift generate a sequence of numbers. We decide the parameters:

  • from: The starting value of the sequence.
  • to: The upper bound the sequence stops before reaching (exclusive).
  • through: The upper bound the sequence includes (inclusive).
  • by: The step value, indicating how much to increment or decrement between values.

Counting Up (Exclusive) Example:

Press enter or click to view image in full size

Output:

  • 1
  • 3
  • 5

--

--

Stanley Miller 
Stanley Miller 

Written by Stanley Miller 

iOS Developer. Author. Fan of the interesting. Written 100+ Swift/SwiftUI articles.