@ -7,13 +7,13 @@
本页包含内容:
- [前缀表达式( Prefix Expressions) ]
- [二元表达式( Binary Expressions) ]
- [赋值表达式( Assignment Operator) ]
- [三元条件运算符( Ternary Conditional Operator) ]
- [类型转换运算符( Type-Casting Operators) ]
- [主要表达式( Primary Expressions) ]
- [后缀表达式( Postfix Expressions) ]
- [ 前缀表达式( Prefix Expressions) ](#prefix_expressions )
- [ 二元表达式( Binary Expressions) ](#binary_expressions )
- [ 赋值表达式( Assignment Operator) ](#assignment_operator )
- [ 三元条件运算符( Ternary Conditional Operator) ](#ternary_conditional_operator )
- [ 类型转换运算符( Type-Casting Operators) ](#type-casting_operators )
- [ 主要表达式( Primary Expressions) ](#primary_expressions )
- [ 后缀表达式( Postfix Expressions) ](#postfix_expressions )
Swift 中存在四种表达式: 前缀( prefix) 表达式, 二元( binary) 表达式, 主要( primary) 表达式和后缀( postfix) 表达式。表达式可以返回一个值, 以及运行某些逻辑( causes a side effect) 。
@ -24,6 +24,7 @@ Swift 中存在四种表达式: 前缀( prefix) 表达式, 二元( binary
> *expression* → *prefix-expression* *binary-expressions(*opt)
> *expression-list* → *expression* | *expression* , *expression-list*
< a name = "prefix_expressions" ></ a >
## 前缀表达式( Prefix Expressions)
前缀表达式由 前缀符号和表达式组成。(这个前缀符号只能接收一个参数)
@ -47,6 +48,7 @@ Swift 标准库支持如下的前缀操作符:
> *prefix-expression* → *in-out-expression*
> *in-out-expression* → & *identifier*
< a name = "binary_expressions" ></ a >
## 二元表达式( Binary Expressions)
二元表达式由 "左边参数" + "二元运算符" + "右边参数" 组成, 它有如下的形式:
@ -124,6 +126,7 @@ Swift 标准库提供了如下的二元运算符:
> *binary-expression* → *type-casting-operator*
> *binary-expression*s → *binary-expression* *binary-expressions*(opt)
< a name = "assignment_operator" ></ a >
## 赋值表达式( Assignment Operator)
The assigment operator sets a new value for a given expression. It has the following form:
@ -144,6 +147,7 @@ The assigment operator sets a new value for a given expression. It has the follo
>
> *assignment-operator* → =
< a name = "ternary_conditional_operator" ></ a >
## 三元条件运算符( Ternary Conditional Operator)
三元条件运算符 是根据条件来获取值。 形式如下:
@ -158,6 +162,7 @@ The assigment operator sets a new value for a given expression. It has the follo
>
> `conditional-operator` → ? `expression` :
< a name = "type-casting_operators" ></ a >
## 类型转换运算符( Type-Casting Operators)
有两种类型转换操作符: as 和 is. 它们有如下的形式:
@ -208,6 +213,7 @@ The check must not be known to be true or false at compile time. The following a
>
> *type-casting-operator* → is *type* | as ?(opt) *type*
< a name = "primary_expressions" ></ a >
## 主要表达式( Primary Expressions)
`主要表达式` 是最基本的表达式。 它们可以跟 前缀表达式,二元表达式,后缀表达式以及其他主要表达式组合使用。
@ -433,6 +439,7 @@ x = .AnotherValue
>
> *wildcard-expression* → _
< a name = "postfix_expressions" ></ a >
## 后缀表达式( Postfix Expressions)
后缀表达式就是在某个表达式的后面加上 操作符。 严格的讲, 每个主要表达式( primary expression) 都是一个后缀表达式