swift - 重载 "."产生错误

标签 swift

我似乎无法重载“。”不确定这是编译器错误还是我正在做的事情:

@infix func . (a: Int, b: Int) -> Int {
  return a * b
}

我得到错误:

函数声明中的预期标识符 大括号语句 block 是未使用的闭包

最佳答案

你不能重载 '.'它是该语言的保留标记。但是,您可以重载 .. 和 ... 运算符。

Operators are made up of one or more of the following characters: /, =, -, +, !, , %, <, >, &, |, ^, ~, and .. That said, the tokens =, ->, //, /, */, ., and the unary prefix operator & are reserved. These tokens can’t be overloaded, nor can they be used to define custom operators.

Language Reference

关于swift - 重载 "."产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24092525/

相关文章:

ios - 从 TableView 重新加载单元格后管理 TableView 单元格,文本字段中的数据不清晰

ios - 导航标题不显示

ios - 音调在 Audikit 4.2 中不播放,但在 4.1 版本中工作正常

ios - 无法将类型 'NSNull' 的值转换为 'NSNumber'

swift - SwiftUI 中 State 和 StateObject 有什么区别?

ios - 刚好输入一个数字后移至下一个 UITextField

objective-c - 从 WKWebView 获取 favicon.co

ios - 如何使用 Alamofire 多部分上传多张图片?

swift - 从 Swift 中的触摸返回坐标

ios - 无法切换 UISwitch 的状态