【问题标题】:max(_:_:) and min(_:_:) in an Int extension in Swift [duplicate]Swift 的 Int 扩展中的 max(_:_:) 和 min(_:_:) [重复]
【发布时间】:2018-11-16 19:44:16
【问题描述】:

为什么 Swift Int 扩展中不允许使用 max(::) 和 min(::),例如:

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

错误提示:Static member 'max' cannot be used on instance of type'Int'

【问题讨论】:

标签: swift max min instancetype


【解决方案1】:

编译器在这里需要一些帮助。它认为你的意思是https://developer.apple.com/documentation/swift/int/1540171-max

正如 Hamish 所说,您可以通过调用 Swift.max 在此上下文中消除歧义以指定全局函数。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-09-23
  • 1970-01-01
  • 2018-01-30
  • 1970-01-01
  • 1970-01-01
  • 2022-11-25
  • 2022-07-26
  • 2016-05-23
相关资源
最近更新 更多