precedencegroup ComparativePrecedence{ //定义运算符优先级
associativity: right
higherThan: LogicalConjunctionPrecedence
}
infix operator ** : ComparativePrecedence
func **(x: Double, p:Double) -> Double{
return pow(x,p)
}
通过这种方式来声明一个运算符,并指定优先级组,优先级组中已经指定了结合性和优先级。
infix(prefix/postfix) operator operator name: precedence group
主要有Bitwise shift,Multiplication,Addition,Range formation,Casting,Nil coalescing,Comparison,Logical conjunction,Ternary,Assignment. 这些优先级组
举例:
infix operator **:AdditionPrecedence
以下是表格的部分截图