<!--
{
  "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(_:)-680jp",
  "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 closed range is
contained within this range.

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

## Parameters

`other`

A closed range to check for containment within this
range.

## Return Value

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

## Discussion

The given closed range is contained within this range if its bounds are
contained within this range. If this range is empty, it cannot contain a
closed range, since closed ranges by definition contain their boundaries.

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

let emptyRange = 3..<3
emptyRange.contains(3...3)   // false
```

> 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)