<!--
{
  "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/Range/contains(_:)-4xxju",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sn8containsySbSnyxGF"
  },
  "title" : "contains(_:)"
}
-->

# contains(_:)

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

```
func contains(_ other: Range<Bound>) -> Bool
```

## Parameters

`other`

A range to check for containment within this range.

## Return Value

`true` if `other` is empty or wholly contained within this
range; otherwise, `false`.

## Discussion

The given range is contained within this range if its bounds are equal to
or within the bounds of this range.

```
let range = 0..<10
range.contains(2..<5)        // true
range.contains(2..<10)       // true
range.contains(2..<12)       // false
```

Additionally, passing any empty range as `other` results in the value
`true`, even if the empty range’s bounds are outside the bounds of this
range.

```
let emptyRange = 3..<3
emptyRange.contains(3..<3)   // true
emptyRange.contains(5..<5)   // true
```

> Complexity: O(1)

---

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)