<!--
{
  "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/clamped(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SN7clamped2toSNyxGAC_tF"
  },
  "title" : "clamped(to:)"
}
-->

# clamped(to:)

Returns a copy of this range clamped to the given limiting range.

```
func clamped(to limits: ClosedRange<Bound>) -> ClosedRange<Bound>
```

## Parameters

`limits`

The range to clamp the bounds of this range.

## Return Value

A new range clamped to the bounds of `limits`.

## Discussion

The bounds of the result are always limited to the bounds of `limits`.
For example:

```
let x: ClosedRange = 0...20
print(x.clamped(to: 10...1000))
// Prints "10...20"
```

If the two ranges do not overlap, the result is a single-element range at
the upper or lower bound of `limits`.

```
let y: ClosedRange = 0...5
print(y.clamped(to: 10...1000))
// Prints "10...10"
```

---

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)