---
title: Strideable
framework: swift
role: symbol
role_heading: Protocol
path: swift/strideable
---

# Strideable

A type representing continuous, one-dimensional values that can be offset and measured.

## Declaration

```swift
protocol Strideable<Stride> : Comparable
```

## Overview

Overview You can use a type that conforms to the Strideable protocol with the stride(from:to:by:) and stride(from:through:by:) functions. For example, you can use stride(from:to:by:) to iterate over an interval of floating-point values: for radians in stride(from: 0.0, to: .pi * 2, by: .pi / 2) {     let degrees = Int(radians * 180 / .pi)     print("Degrees: \(degrees), radians: \(radians)") } // Degrees: 0, radians: 0.0 // Degrees: 90, radians: 1.5707963267949 // Degrees: 180, radians: 3.14159265358979 // Degrees: 270, radians: 4.71238898038469 The last parameter of these functions is of the associated Stride type—the type that represents the distance between any two instances of the Strideable type. 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. var sum = 0 for x in 1...100 {     sum += x } // sum == 5050

let digits = (0..<10).map(String.init) // ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] Conforming to the Strideable Protocol To add Strideable conformance to a custom type, choose a Stride type that can represent the distance between two instances and implement the advanced(by:) and distance(to:) methods. For example, this hypothetical Date type stores its value as the number of days before or after January 1, 2000: struct Date: Equatable, CustomStringConvertible {     var daysAfterY2K: Int

var description: String {         // ...     } } The Stride type for Date is Int, inferred from the parameter and return types of advanced(by:) and distance(to:): extension Date: Strideable {     func advanced(by n: Int) -> Date {         var result = self         result.daysAfterY2K += n         return result     }

func distance(to other: Date) -> Int {         return other.daysAfterY2K - self.daysAfterY2K     } } The Date type can now be used with the stride(from:to:by:) and stride(from:through:by:) functions and as the bounds of an iterable range. let startDate = Date(daysAfterY2K: 0)   // January 1, 2000 let endDate = Date(daysAfterY2K: 15)    // January 16, 2000

for date in stride(from: startDate, to: endDate, by: 7) {     print(date) } // January 1, 2000 // January 8, 2000 // January 15, 2000 important: The Strideable protocol provides default implementations for the equal-to (==) and less-than (<) operators that depend on the Stride type’s implementations. If a type conforming to Strideable is its own Stride type, it must provide concrete implementations of the two operators to avoid infinite recursion.

## Topics

### Getting an Offset Value

- [advanced(by:)](swift/strideable/advanced(by:).md)
- [+(_:_:)](swift/strideable/+(_:_:)-8m1px.md)
- [+(_:_:)](swift/strideable/+(_:_:)-94mlm.md)
- [-(_:_:)](swift/strideable/-(_:_:)-1kjns.md)
- [-(_:_:)](swift/strideable/-(_:_:)-2mot7.md)

### Comparing Values

- [distance(to:)](swift/strideable/distance(to:).md)

### Operators

- [+=(_:_:)](swift/strideable/+=(_:_:).md)
- [-=(_:_:)](swift/strideable/-=(_:_:).md)

### Associated Types

- [Stride](swift/strideable/stride.md)

## Relationships

### Inherits From

- [Comparable](swift/comparable.md)
- [Equatable](swift/equatable.md)

### Inherited By

- [BinaryFloatingPoint](swift/binaryfloatingpoint.md)
- [BinaryInteger](swift/binaryinteger.md)
- [FixedWidthInteger](swift/fixedwidthinteger.md)
- [FloatingPoint](swift/floatingpoint.md)
- [SignedInteger](swift/signedinteger.md)
- [UnsignedInteger](swift/unsignedinteger.md)

### Conforming Types

- [AutoreleasingUnsafeMutablePointer](swift/autoreleasingunsafemutablepointer.md)
- [Double](swift/double.md)
- [Float](swift/float.md)
- [Float16](swift/float16.md)
- [Float80](swift/float80.md)
- [Int](swift/int.md)
- [Int128](swift/int128.md)
- [Int16](swift/int16.md)
- [Int32](swift/int32.md)
- [Int64](swift/int64.md)
- [Int8](swift/int8.md)
- [UInt](swift/uint.md)
- [UInt128](swift/uint128.md)
- [UInt16](swift/uint16.md)
- [UInt32](swift/uint32.md)
- [UInt64](swift/uint64.md)
- [UInt8](swift/uint8.md)
- [UnsafeMutablePointer](swift/unsafemutablepointer.md)
- [UnsafeMutableRawPointer](swift/unsafemutablerawpointer.md)
- [UnsafePointer](swift/unsafepointer.md)
- [UnsafeRawPointer](swift/unsaferawpointer.md)

## See Also

### Basic Arithmetic

- [AdditiveArithmetic](swift/additivearithmetic.md)
- [Numeric](swift/numeric.md)
- [SignedNumeric](swift/signednumeric.md)
