最近在看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