Former Swift 3 code for operator was:
infix operator × {associativity left precedence 150}
But now, as per Xcode 8 beta 6, this generate the following warning:
"operator should not be declared with body"
What's the right way to use precedencegroup predicate as no doc exists right now?
I have tried this, but does not work:
infix operator × : times
precedencegroup times {
associativity: left
precedence: 150
}
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):
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:It is defined as:
For a full list of standard library precedence groups, as well as more info about this change, see the evolution proposal.