<!--
{
  "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/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: Range<Bound>) -> Range<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: Range = 0..<20
print(x.clamped(to: 10..<1000))
// Prints "10..<20"
```

If the two ranges do not overlap, the result is an empty range within the
bounds of `limits`.

```
let y: Range = 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)