Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

max(_:_:) and min(_:_:) in an Int extension in Swift [duplicate]

Why are max(::) and min(::) not allowed in a Swift Int extension, such as:

extension Int {
    func some(low: Int, high: Int) -> Int {
        return max(low, high)
    }
}

The error says: Static member 'max' cannot be used on instance of type'Int'

like image 570
iKK Avatar asked Sep 14 '25 09:09

iKK


1 Answers

The compiler needs some help here. It thinks you mean https://developer.apple.com/documentation/swift/int/1540171-max

As Hamish says, you can disambiguate within this context to specify the global function by calling it Swift.max.

like image 114
matt Avatar answered Sep 17 '25 01:09

matt