I want to add default implementation for Int/Float/Double value.
protocol ValueLimit { associatedtype T where T: Comparable func limit(from minValue: T, to maxValue: T) -> T } extension ValueLimit { func limit(from minValue: T, to maxValue: T) -> T { return Swift.max(Swift.min(self as! Self.T, maxValue), minValue) } } extension Int: ValueLimit { typealias T = Int } extension Float: ValueLimit { typealias T = Float } extension Double: ValueLimit { typealias T = Double } I belive there is a better way, which can simply use empty extension extension Int: ValueLimit {} to do this, without typealias T = Int, but I don't know how to do this.