Comparable

extension Comparable
  • Limit a value to the specified range.

    4.clamped(to: 1..<10) // 4
    11.clamped(to: 1..<10) // 10
    0.clamped(to: 1..<10) // 1
    

    Declaration

    Swift

    public func clamped(to limits: ClosedRange<Self>) -> Self

    Parameters

    limits

    Bounds of alowable values.

    Return Value

    The clamped value