---
title: "clamped(to:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/closedrange/clamped(to:)"
---

# clamped(to:)

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

## Declaration

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

## Parameters

- `limits`: The range to clamp the bounds of this range.

## Return Value

Return Value A new range clamped to the bounds of limits.

## Discussion

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"
