最近在看swift,都知道快速学习一门语言的根本就是看代码,写代码。html
因而乎看到一个奇特的关键字infix. 不明白是干啥的额,最终找到了答案swift
infix是能够自定义运算符的关键字啊学习
例如定义个?运算符code
infix operator ? { associativity left precedence 140 } func ?(left: [Int], right: [Int]) -> [Int] { var minus = [Int](count: left.count, repeatedValue: 0) assert(left.count == right.count, "vector of same length only") for (key, v) in enumerate(left) { minus[key] = left[key] - right[key] } return minus }
更多内容能够参考http://www.cocoachina.com/swift/20150204/11091.htmlhtm