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

# contains(_:)

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

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

## Parameters

`other`

A range to check for containment within this closed
range.

## Return Value

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

## Discussion

The given range is contained within this closed range if the elements of
the range are all contained within this closed range.

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

// Note that `5..<11` contains 5, 6, 7, 8, 9, and 10.
range.contains(5..<11)    // true
```

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
closed range.

```
range.contains(3..<3)     // true
range.contains(20..<20)   // 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)