<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/RangeExpression",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SX"
  },
  "title" : "RangeExpression"
}
-->

# RangeExpression

A type that can be used to slice a collection.

```
protocol RangeExpression<Bound>
```

## Overview

A type that conforms to `RangeExpression` can convert itself to a
`Range<Bound>` of indices within a given collection.

## Topics

### Operators

[`static func ~= (Self, Self.Bound) -> Bool`](/documentation/Swift/RangeExpression/~=(_:_:))

Returns a Boolean value indicating whether a value is included in a
range.

### Associated Types

[`associatedtype Bound : Comparable`](/documentation/Swift/RangeExpression/Bound)

The type for which the expression describes a range.

### Instance Methods

[`func contains(Self.Bound) -> Bool`](/documentation/Swift/RangeExpression/contains(_:))

Returns a Boolean value indicating whether the given element is contained
within the range expression.

[`func relative<C>(to: C) -> Range<Self.Bound>`](/documentation/Swift/RangeExpression/relative(to:))

Returns the range of indices described by this range expression within
the given collection.

## Relationships

### Conforming Types

[`PartialRangeThrough`](/documentation/Swift/PartialRangeThrough)

[`ClosedRange`](/documentation/Swift/ClosedRange)

[`PartialRangeUpTo`](/documentation/Swift/PartialRangeUpTo)

[`PartialRangeFrom`](/documentation/Swift/PartialRangeFrom)

[`Range`](/documentation/Swift/Range)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)