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'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With