---
title: "CMTimeClampToRange(_:range:)"
framework: Core Media
role: symbol
role_heading: Function
platforms: [iOS 4.0+, iPadOS 4.0+, Mac Catalyst 13.1+, macOS 10.7+, tvOS 9.0+, visionOS 1.0+, watchOS 6.0+]
path: "coremedia/cmtimeclamptorange(_:range:)"
---

# CMTimeClampToRange(_:range:)

Returns the nearest time value inside the time range.

## Declaration

```swift
func CMTimeClampToRange(_ time: CMTime, range: CMTimeRange) -> CMTime
```

## Parameters

- `time`: The time to clamp.
- `range`: The time range to examine.

## Return Value

Return Value A time structure inside the time range.

## Discussion

Discussion The function returns the times inside the range you specify unmodified. Times before the start and after the end time of the time range return the start and end time of the range. If the CMTimeRange argument is empty, this function returns an invalid CMTime. If the given CMTime is invalid, the function returns an invalid CMTime.

## See Also

### Utility Functions

- [CMTimeMapDurationFromRangeToRange(_:fromRange:toRange:)](coremedia/cmtimemapdurationfromrangetorange(_:fromrange:torange:).md)
- [CMTimeMapTimeFromRangeToRange(_:fromRange:toRange:)](coremedia/cmtimemaptimefromrangetorange(_:fromrange:torange:).md)
- [CMTimeRangeCopyAsDictionary(_:allocator:)](coremedia/cmtimerangecopyasdictionary(_:allocator:).md)
- [CMTimeRangeCopyDescription(allocator:range:)](coremedia/cmtimerangecopydescription(allocator:range:).md)
- [CMTimeRangeShow(_:)](coremedia/cmtimerangeshow(_:).md)
