A type representing continuous, one-dimensional values that can be offset and measured.
- Xcode 6.0.1+
- Swift Standard Library
You can use a type that conforms to the
Strideable protocol with the
stride(from: functions. For example, you can use
stride(from: to iterate over an interval of floating-point values:
The last parameter of these functions is of the associated
Stride type—the type that represents the distance between any two instances of the
Types that have an integer
Stride can be used as the boundaries of a countable range or as the lower bound of an iterable one-sided range. For example, you can iterate over a range of
Int and use sequence and collection methods.
Conforming to the Strideable Protocol
Strideable conformance to a custom type, choose a
Stride type that can represent the distance between two instances and implement the
distance(to:) methods. For example, this hypothetical
Date type stores its value as the number of days before or after January 1, 2000:
Stride type for
Int, inferred from the parameter and return types of
Date type can now be used with the
stride(from: functions and as the bounds of an iterable range.