We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
If this tool helped you, you can buy us a coffee ☕
Free online quick reference cheat sheet for Objective-C operator precedence and associativity. Easily check execution order and evaluation rules.
[]Postfix & AccessLeft-to-right用于数组或集合下标访问;在 Objective-C 中方括号也用于向对象发送消息。
items[index] / [view setNeedsLayout]()Postfix & AccessLeft-to-right改变表达式求值顺序,或调用 C 函数、Block、方法返回的函数指针。
(a + b) * c / NSLog(@"%@", text).Postfix & AccessLeft-to-right访问结构体成员,也常用于 Objective-C 属性的点语法。
point.x / object.title->Postfix & AccessLeft-to-right通过结构体指针访问成员。
node->next+aUnaryRight-to-left保留数值本身,通常用于明确表达正值。
+count-aUnaryRight-to-left返回操作数的相反数。
-offset++a / a++UnaryRight-to-left将变量加 1;前置形式先递增再取值,后置形式先取值再递增。
++index / index++--a / a--UnaryRight-to-left将变量减 1;前置形式先递减再取值,后置形式先取值再递减。
--index / index--(type)UnaryRight-to-left把表达式显式转换为指定 C 或 Objective-C 指针类型。
(UIView *)sender*aUnaryRight-to-left读取指针指向位置的值。
*buffer&aUnaryRight-to-left取得变量、结构体成员或对象指针变量的地址。
&error!UnaryRight-to-left对布尔或条件表达式取反。
!isHidden~UnaryRight-to-left对整数每一位取反。
~masksizeofUnaryRight-to-left返回类型或表达式占用的字节数,结果类型为 size_t。
sizeof(CGPoint)*MultiplicativeLeft-to-right两个数值相乘。
width * scale/MultiplicativeLeft-to-right执行数值除法;整数除法会截断小数部分。
total / count%MultiplicativeLeft-to-right返回整数相除后的余数。
index % 2+AdditiveLeft-to-right数值相加,也可用于指针与整数的偏移。
x + y-AdditiveLeft-to-right数值相减,或两个指针相减得到元素距离。
max - min<<ShiftLeft-to-right将整数二进制位向左移动指定数量。
1 << bit>>ShiftLeft-to-right将整数二进制位向右移动指定数量。
flags >> 1>RelationalLeft-to-right判断左操作数是否大于右操作数。
count > limit>=RelationalLeft-to-right判断左操作数是否大于或等于右操作数。
count >= minimum<RelationalLeft-to-right判断左操作数是否小于右操作数。
index < total<=RelationalLeft-to-right判断左操作数是否小于或等于右操作数。
index <= lastIndex==EqualityLeft-to-right比较两个值是否相等;对象内容比较通常应使用 isEqual: 等方法。
status == 200!=EqualityLeft-to-right比较两个值是否不相等。
object != nil&BitwiseLeft-to-right对两个整数逐位执行与运算。
options & NSCaseInsensitiveSearch^BitwiseLeft-to-right对两个整数逐位执行异或运算。
mask ^ flag|BitwiseLeft-to-right对两个整数逐位执行或运算,常用于组合选项位。
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight&&LogicalLeft-to-right短路与;左侧为假时不再计算右侧表达式。
view != nil && !view.hidden||LogicalLeft-to-right短路或;左侧为真时不再计算右侧表达式。
cached || [self reloadData]?:ConditionalRight-to-left根据条件在两个表达式之间选择一个结果。
title.length ? title : @"Untitled"=AssignmentRight-to-left把右侧表达式结果写入左侧变量或属性。
self.title = title/=AssignmentRight-to-left将左值除以右侧表达式后再赋回左值。
scale /= 2*=AssignmentRight-to-left将左值乘以右侧表达式后再赋回左值。
height *= ratio%=AssignmentRight-to-left将左值取余后再赋回左值。
index %= count+=AssignmentRight-to-left将右侧表达式加到左值上并赋回。
x += delta-=AssignmentRight-to-left从左值中减去右侧表达式并赋回。
remaining -= used<<=AssignmentRight-to-left左移指定数量后赋回左值。
flags <<= 1>>=AssignmentRight-to-left右移指定数量后赋回左值。
flags >>= 1&=AssignmentRight-to-left执行按位与后赋回左值。
options &= allowed^=AssignmentRight-to-left执行按位异或后赋回左值。
mask ^= flag|=AssignmentRight-to-left执行按位或后赋回左值。
options |= UIViewAnimationOptionCurveEaseInOut,CommaLeft-to-right从左到右依次求值多个表达式,整个表达式结果为最后一个表达式的值。
i++, j--In Objective-C development, operator precedence and associativity directly impact the evaluation of expressions. Even a slight oversight can lead to logical errors that are difficult to debug. This tool provides a complete Objective-C operator precedence cheat sheet, clearly listing all operators from highest to lowest precedence along with their associativity. It helps developers quickly reference and accurately understand evaluation rules, avoiding coding issues caused by precedence confusion.
* has a higher precedence than addition +, so the expression 2 + 3 * 4 evaluates to 14, not 20. The assignment operator = is right-associative, meaning a = b = c is equivalent to a = (b = c).() have the highest precedence. They can force a change in the default evaluation order of an expression and are the most direct way to clarify your calculation intent.+ is left-associative, so a + b + c is evaluated as (a + b) + c. Conversely, the assignment operator = is right-associative, so a = b = 0 will first assign 0 to b, and then assign the result to a.This cheat sheet only covers standard Objective-C operators and may not include compiler extensions or custom operators for specific platforms. In actual coding, even if you are familiar with precedence rules, it is highly recommended to use parentheses to explicitly define the evaluation order when mixing multiple operators. This improves code readability and maintainability. This tool is a pure static content display, does not collect any user data, and poses no privacy risks.
Mastering operator precedence is the foundation of writing unambiguous code. Common pitfalls include: logical AND && has a higher precedence than logical OR ||; bitwise AND & has a lower precedence than the equality operator ==; and the conditional (ternary) operator ?: has a relatively low precedence and is right-associative. In complex expressions, writing unit tests or using static analysis tools to verify evaluation results can effectively prevent potential precedence traps.

JSON Formatter
Process JSON data online: format, minify, and validate to boost your development and debugging efficiency.

JSON to Objective-C Class Generator
Automatically generate Objective-C model classes from JSON data for iOS and macOS development.

URL to JSON Parser
Parse URL strings into structured JSON to quickly extract key information like protocols, parameters, and paths.

Code Compare
Professionally compare differences between two texts or code snippets. Highlights additions, deletions, and modifications to assist with code review, document merging, and version control.

JSON Formatter
Process JSON data online: format, minify, and validate to boost your development and debugging efficiency.

JSON to Objective-C Class Generator
Automatically generate Objective-C model classes from JSON data for iOS and macOS development.

URL to JSON Parser
Parse URL strings into structured JSON to quickly extract key information like protocols, parameters, and paths.

Code Compare
Professionally compare differences between two texts or code snippets. Highlights additions, deletions, and modifications to assist with code review, document merging, and version control.

PYC Decompiler
Restore Python bytecode .pyc files into readable source code for easy code auditing and learning. Supports mainstream versions.