As per SE-0077, the precedence of an operator is no longer determined by a magic number – instead you now use the higherThan
and (if the group resides in another module) lowerThan
precedencegroup
relationships in order to define precedence relative to other groups.
For example (from the evolution proposal):
// module Swift
precedencegroup Additive { higherThan: Range }
precedencegroup Multiplicative { higherThan: Additive }
// module A
precedencegroup Equivalence {
higherThan: Comparative
lowerThan: Additive // possible, because Additive lies in another module
}
infix operator ~ : Equivalence
1 + 2 ~ 3 // same as (1 + 2) ~ 3, because Additive > Equivalence
1 * 2 ~ 3 // same as (1 * 2) ~ 3, because Multiplicative > Additive > Equivalence
1 < 2 ~ 3 // same as 1 < (2 ~ 3), because Equivalence > Comparative
1 += 2 ~ 3 // same as 1 += (2 ~ 3), because Equivalence > Comparative > Assignment
1 ... 2 ~ 3 // error, because Range and Equivalence are unrelated
Although in your case, as it appears that your operator is used for multiplication, you could simply use the standard library's MultiplicationPrecedence
group, which is used for the *
operator:
infix operator × : MultiplicationPrecedence
It is defined as:
precedencegroup MultiplicationPrecedence {
associativity: left
higherThan: AdditionPrecedence
}
For a full list of standard library precedence groups, as well as more info about this change, see the evolution proposal.