Precedence of standard Swift operators
suggest changeOperators that bound tighter (higher precedence) are listed first.
Operators | Precedence group (≥3.0) | Precedence | Associativity |
|————|——————|–––––––––––––|—————| | . | | ∞ | left | ?, \!, ++, --, [], (), {} | (postfix) | | | | \!, ~, \+, \-, ++, -- | (prefix) | | | | ~> (swift ≤2.3) | | 255 | left | <<, >> | BitwiseShiftPrecedence | 160 | none | \*, /, %, &, &* | MultiplicationPrecedence | 150 | left | \+, \-, |, ^, &+, &- | AdditionPrecedence | 140 | left | ..., ..< | RangeFormationPrecedence | 135 | none | is, as, as?, as! | CastingPrecedence | 132 | left | ?? | NilCoalescingPrecedence | 131 | right | \<, <=, \>, >=, ==, !=, ===, !==, ~= | ComparisonPrecedence | 130 | none | | && | LogicalConjunctionPrecedence | 120 | left | || | LogicalDisjunctionPrecedence | 110 | left | | DefaultPrecedence* | | none | ?…: | TernaryPrecedence | 100 | right | =, +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^= | AssignmentPrecedence | 90 | right, assignment | -> | FunctionArrowPrecedence | | right
- The
DefaultPrecedenceprecedence group is higher thanTernaryPrecedence, but is unordered with the rest of the operators. Other than this group, the rest of the precedences are linear. - This table can be also be found on Apple’s API reference
- The actual definition of the precedence groups can be found in the source code on GitHub