词法结构
--------------------------------------
> 空白语法
>
> 空白 → [空白项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/whitespace-item) [空白](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/whitespace) opt
>
> 空白项 → [断行符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/line-break)
>
> 空白项 → [注释](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/comment)
>
> 空白项 → [多行注释](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-comment)
>
> 空白项 →U+0000, U+0009, U+000B, U+000C, 或者 U+0020
>
> 断行符 → U+000A
>
> 断行符 → U+000D
>
> 断行符 → U+000D 接着是 U+000A
>
> 注释 → `//` [注释内容](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/comment-text) [断行符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/line-break)
>
> 多行注释 → `/*` [多行注释内容](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-comment-text) `*/`
>
> 注释内容 → [注释内容项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/comment-text-item) [注释内容](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/comment-text) opt
>
> 注释内容项 → 任何 Unicode 标量值, 除了 U+000A 或者 U+000D
>
> 多行注释内容 → [多行注释内容项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-comment-text-item) [多行注释内容](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-comment-text) opt
>
> 多行注释内容项 → [多行注释](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-comment)
>
> 多行注释内容项 → [注释内容项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/comment-text-item)
>
> 多行注释内容项 → 任何 Unicode 标量值, 除了 `/*` 或者 `*/`
> 标识符语法
>
> 标识符 → [头部标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-head)[标识符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-characters) opt
>
> 标识符 → `` ` `` [头部标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-head) [标识符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-characters) opt `` ` ``
>
> 标识符 → [隐式参数名](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/implicit-parameter-name)
>
> 标识符列表 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)| [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `,` [标识符列表](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-list)
>
> 头部标识符 →大写或小写字母 A - Z 头部标识符
>
> 头部标识符 → `_`
>
> 头部标识符 →U+00A8, U+00AA, U+00AD, U+00AF, U+00B2--U+00B5, 或者 U+00B7--U+00BA
>
> 头部标识符 →U+00BC--U+00BE, U+00C0--U+00D6, U+00D8--U+00F6, 或者 U+00F8--U+00FF
>
> 头部标识符 →U+0100--U+02FF, U+0370--U+167F, U+1681--U+180D, 或者 U+180F--U+1DBF
>
> 头部标识符 →U+1E00--U+1FFF
>
> 头部标识符 →U+200B--U+200D, U+202A--U+202E, U+203F--U+2040, U+2054, 或者 U+2060--U+206F
>
> 头部标识符 →U+2070--U+20CF, U+2100--U+218F, U+2460--U+24FF, 或者 U+2776--U+2793
>
> 头部标识符 →U+2C00--U+2DFF 或者 U+2E80--U+2FFF
>
> 头部标识符 →U+3004--U+3007, U+3021--U+302F, U+3031--U+303F, 或者 U+3040--U+D7FF
>
> 头部标识符 →U+F900--U+FD3D, U+FD40--U+FDCF, U+FDF0--U+FE1F, 或者 U+FE30--U+FE44
>
> 头部标识符 →U+FE47--U+FFFD
>
> 头部标识符 →U+10000--U+1FFFD, U+20000--U+2FFFD, U+30000--U+3FFFD, 或者 U+40000--U+4FFFD
>
> 头部标识符 →U+50000--U+5FFFD, U+60000--U+6FFFD, U+70000--U+7FFFD, 或者 U+80000--U+8FFFD
>
> 头部标识符 →U+90000--U+9FFFD, U+A0000--U+AFFFD, U+B0000--U+BFFFD, 或者 U+C0000--U+CFFFD
>
> 头部标识符 →U+D0000--U+DFFFD 或者 U+E0000--U+EFFFD
>
> 标识符字符组 → 数值 0 - 9
>
> 标识符字符组 → U+0300--U+036F, U+1DC0--U+1DFF, U+20D0--U+20FF, 或者 U+FE20--U+FE2F
>
> 标识符字符组 → [头部标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-head)
>
> 标识符字符组 → [标识符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-character) [标识符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-characters) opt
>
> 隐式参数名 → `$` [十进制数字列表](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits)
> 字面量语法
>
> 字面量 → [数值字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/numeric-literal) | [字符串字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/string-literal) | [布尔值字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/boolean-literal) | [nil字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/nil-literal)
>
> 数值字面量 → `-`opt [整数字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/integer-literal) | `-`opt [浮点数字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/floating-point-literal)
>
> 布尔值字面量 → `true`| `false`
>
> nil字面量 → `nil`
---
> 整数字面量语法
>
> 整数字面量 → [二进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/binary-literal)
>
> 整数字面量 → [八进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/octal-literal)
>
> 整数字面量 → [十进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal)
>
> 整数字面量 → [十六进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-literal)
>
> 二进制字面量 → `0b`[二进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/binary-digit) [二进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/binary-literal-characters) opt
>
> 二进制数字 → 数值 0 到 1
>
> 二进制字面量字符组 → [二进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/binary-digit) | `_`
>
> 二进制字面量字符组 → [二进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/binary-literal-character) [二进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/binary-literal-characters) opt
>
> 八进制字面量 → `0o` [八进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/octal-digit) [八进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/octal-literal-characters) opt
>
> 八进制数字 → 数值 0 到 7
>
> 八进制字面量字符组 → [八进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/octal-digit) | `_`
>
> 八进制字面量字符组 → [八进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/octal-literal-character) [八进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/octal-literal-characters) opt
>
> 十进制字面量 → [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digit) [十进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal-characters) opt
>
> 十进制数字 → 数值 0 到 9
>
> 十进制数字 → [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digit) [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits) opt
>
> 十进制字面量字符组 → [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digit) | `_`
>
> 十进制字面量字符组 → [十进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal-character) [十进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal-characters) opt
>
> 十六进制字面量 → `0x` [十六进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-digit) [十六进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-literal-characters) opt
>
> 十六进制数字 →数值 0 到 9, 字母 a 到 f, 或 A 到 F
>
> 十六进制字面量字符组 → [十六进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-digit) | `_`
>
> 十六进制字面量字符组 → [十六进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-literal-character) [十六进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-literal-characters) opt
> 浮点数字面量语法
>
> 浮点数字面量 → [十进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal) [十进制分数](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-fraction) opt [十进制指数](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-exponent) opt
>
> 浮点数字面量 → [十六进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-literal) [十六进制分数](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-fraction) opt [十六进制指数](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-exponent)
>
> 十进制分数 → `.` [十进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal)
>
> 十进制指数 → [浮点数e](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/floating-point-e) [签名](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/sign) opt [十进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal)
>
> 十六进制分数 → `.` [十六进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-digit) [十六进制字面量字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/hexadecimal-literal-characters) opt
>
> 十六进制指数 → [浮点数p](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/floating-point-p) [签名](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/sign) opt [十进制字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-literal)
>
> 浮点数e → `e`| `E`
>
> 浮点数p → `p`| `P`
>
> 签名 → `+` | `-`
---
> 字符串字面量语法
>
> 字符串字面量 → [静态字符串字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/static-string-literal) | [插值字符串字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/interpolated-string-literal)
>
> 静态字符串字面量 → `"` [引用文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/quoted-text) opt `"`
>
> 静态字符串字面量 → `"""` [多行引用文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-quoted-text) opt `"""`
>
> 引用文本 → [引用文本项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/quoted-text-item) [引用文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/quoted-text) opt
>
> 引用文本项 → [转义字符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/escaped-character)
>
> 引用文本项 →除了以外的所有 Unicode 字符`"`, `\`, U+000A, 或者 U+000D
>
> 多行引用文本 → [多行引用文本项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-quoted-text-item) [多行引用文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-quoted-text) opt
>
> 多行引用文本项 → [转义字符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/escaped-character)
>
> 多行引用文本项 → 除了以外的所有 Unicode 字符 `\`
>
> 多行引用文本项 → [转义字符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/escaped-newline)
>
> 插值字符串字面量 → `"` [插值文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/interpolated-text) opt `"`
>
> 插值字符串字面量 → `"""` [多行引用文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-interpolated-text) opt `"""`
>
> 插值文本 → [插值文本项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/interpolated-text-item) [插值文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/interpolated-text) opt
>
> 插值文本项 → `\(` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)` | [引用文本项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/quoted-text-item)
>
> 多行插值文本 → [多行插值文本项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-interpolated-text-item) [多行插值文本](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-interpolated-text) opt
>
> 多行插值文本项 → `\(` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)` | [多行引用文本项](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/multiline-quoted-text-item)
>
> 转义字符 → `\0` | `\\` | `\t` | `\n` | `\r` | `\"` | `\'`
>
> 转义字符 → `\u` `{` [ Unicode 标量数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/unicode-scalar-digits) `}`
>
> Unicode 标量数字 → 在1到8个十六进制数字之间
>
> 转义换行 → `\` [空白区](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/whitespace) opt [断行符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/line-break)
> 运算符语法
>
> 运算符 → [头部运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator-head)[运算符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator-characters) opt
>
> 运算符 → [头部点运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/dot-operator-head) [头部点运算符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/dot-operator-characters)
>
> 头部运算符 → `/` |`=` | `-` | `+` | `!` | `*` | `%` | `<` | `>` | `&` | `|` | `^` | `~` | `?`
>
> 头部运算符 →U+00A1--U+00A7
>
> 头部运算符 →U+00A9 或者 U+00AB
>
> 头部运算符 →U+00AC 或者 U+00AE
>
> 头部运算符 →U+00B0--U+00B1, U+00B6, U+00BB, U+00BF, U+00D7, 或者 U+00F7
>
> 头部运算符 →U+2016--U+2017 或者 U+2020--U+2027
>
> 头部运算符 →U+2030--U+203E
>
> 头部运算符 →U+2041--U+2053
>
> 头部运算符 →U+2055--U+205E
>
> 头部运算符 →U+2190--U+23FF
>
> 头部运算符 →U+2500--U+2775
>
> 头部运算符 →U+2794--U+2BFF
>
> 头部运算符 →U+2E00--U+2E7F
>
> 头部运算符 →U+3001--U+3003
>
> 头部运算符 →U+3008--U+3030
>
> 运算符字符组 → [头部运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator-head)
>
> 运算符字符组 → U+0300--U+036F
>
> 运算符字符组 → U+1DC0--U+1DFF
>
> 运算符字符组 → U+20D0--U+20FF
>
> 运算符字符组 → U+FE00--U+FE0F
>
> 运算符字符组 → U+FE20--U+FE2F
>
> 运算符字符组 → U+E0100--U+E01EF
>
> 运算符字符组 → [运算符字符组 ](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator-character) [运算符字符组 ](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator-characters) opt
>
> 头部点运算符 → `.`
>
> 点运算符字符组 → `.` | [运算符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator-character)
>
> 点运算符字符组 → [点运算符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/dot-operator-character) [点运算符字符组](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/dot-operator-characters) opt
>
> 二元运算符 → [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
>
> 前缀运算符 → [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
>
> 前缀运算符 → [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
类型
--------------------------
> 类型语法
>
> 类型 → [数组类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/array-type)
>
> 类型 → [字典类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/dictionary-type)
>
> 类型 → [函数类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/function-type)
>
> 类型 → [类型标识](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier)
>
> 类型 → [元组类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/tuple-type)
>
> 类型 → [可选类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/optional-type)
>
> 类型 → [隐式解析可选类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/implicitly-unwrapped-optional-type)
>
> 类型 → [协议合成类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/protocol-composition-type)
>
> 类型 → [元型类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/metatype-type)
>
> 类型 → `任意类型`
>
> 类型 → `自身类型`
>
> 类型 → `(` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) `)`
---
> 类型注解语法
>
> 类型注解 → `:`[特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `输入输出参数`opt [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
---
> 类型标识符语法
>
> 类型标识符 → [类型名称](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-name) [泛型参数子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument-clause) opt | [类型名称](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-name) [泛型参数子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument-clause) opt `.` [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier)
>
> 类型名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
---
> 元组类型语法
>
> 元组类型 → `(` `)` | `(`[元组类型语法](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/tuple-type-element) `,` [元组类型元素列表](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/tuple-type-element-list) `)`
>
> 元组类型元素列表 → [元组类型元素](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/tuple-type-element) | [元组类型元素](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/tuple-type-element) `,` [元组类型元素列表](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/tuple-type-element-list)
>
> 元组类型元素 → [元素名称](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/element-name) [类型注解](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) | [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> 元素名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
> 函数类型语法
>
> 函数类型 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [函数类型参数子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/function-type-argument-clause)`throws`opt `->` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> 函数类型 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [函数类型参数子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/function-type-argument-clause) `rethrows` `->` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> 函数类型参数子句 → `(` `)`
>
> 函数类型参数子句 → `(` [函数类型参数列表](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/function-type-argument-list) `...`opt `)`
>
> 函数类型参数列表 → [函数类型参数](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/function-type-argument) | [函数类型参数](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/function-type-argument) `,`[函数类型参数列表](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/function-type-argument-list)
>
> 函数类型参数 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `inout`opt [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) | [参数标签](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/argument-label) [类型注解](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation)
>
> 参数标签 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
---
> 数组类型语法
>
> 数组类型 → `[` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) `]`
---
> 字典类型语法
>
> 字典类型 → `[`[类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) `:` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) `]`
---
> 可选类型语法
>
> 可选类型 → [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) `?`
---
> 隐式解析可选类型语法
>
> 隐式解析可选类型 → [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) `!`
---
> 协议合成类型语法
>
> 协议合成类型 → [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) `&` [协议合成延续](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/protocol-composition-continuation)
>
> 协议合成延续 → [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) | [协议合成类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/protocol-composition-type)
---
> 元类型语法
>
> 元类型 → [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)`.` `Type` | [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) `.` `Protocol`
---
> 类型继承子句语法
>
> 类型继承子句 → `:` [类型继承列表](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-list)
>
> 类型继承列表 → [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) | [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) `,` [类型继承列表](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-list)
表达式
--------------------------------
> 表达式语法
>
> 表达式 → [try运算符](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/try-operator) opt [前缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/prefix-expression) [二元表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/binary-expressions) opt
>
> 表达式列表 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) | [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `,` [表达式列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression-list)
---
> 前缀表达式语法
>
> 前缀表达式 → [前缀表达式](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/prefix-operator) opt [前缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression)
>
> 前缀表达式 → [输入输出表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/in-out-expression)
>
> 输入输出表达式 → `&` [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
---
> try 表达式语法
>
> try 表达式 → `try` |`try` `?` | `try` `!`
---
> 二元表达式语法
>
> 二元表达式 → [二元运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/binary-operator) [前缀运算符](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/prefix-expression)
>
> 二元表达式 → [赋值运算符](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/assignment-operator) [ try 运算符](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/try-operator) opt [前缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/prefix-expression)
>
> 二元表达式 → [条件运算符](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/conditional-operator) [ try 表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/try-operator) opt [前缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/prefix-expression)
>
> 二元表达式 → [类型转换表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/type-casting-operator)
>
> 二元表达式 → [二元表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/binary-expression) [二元表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/binary-expressions) opt
---
> 赋值表达式语法
>
> 赋值表达式 → `=`
> 条件运算符语法
>
> 条件运算符 → `?` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `:`
---
> 类型转换运算符语法
>
> 类型转换运算符 → `is` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> 类型转换运算符 → `as` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> 类型转换运算符 → `as` `?` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> 类型转换运算符 → `as` `!` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
---
> 基本表达式语法
>
> 基本表达式 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) [泛型参数子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument-clause) opt
>
> 基本表达式 → [字面量表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/literal-expression)
>
> 基本表达式 → [ self 表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/self-expression)
>
> 基本表达式 → [超类表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/superclass-expression)
>
> 基本表达式 → [闭包表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-expression)
>
> 基本表达式 → [圆括号表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/parenthesized-expression)
>
> 基本表达式 → [元组表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/tuple-expression)
>
> 基本表达式 → [隐式成员表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/implicit-member-expression)
>
> 基本表达式 → [通配符表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/wildcard-expression)
>
> 基本表达式 → [key-path表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-expression)
>
> 基本表达式 → [选择器表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/selector-expression)
>
> 基本表达式 → [key-path字符串表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-string-expression)
---
> 字面量表达式语法
>
> 字面量表达式 → [字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/literal)
>
> 字面量表达式 → [数组字面量](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/array-literal) | [字典字面量](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/dictionary-literal) | [练习场字面量](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/playground-literal)
>
> 字面量表达式 → `#file` | `#line` | `#column` | `#function`
>
> 数组字面量 → `[` [数组字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/array-literal-items) opt `]`
>
> 数组字面量项 → [数组字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/array-literal-item) `,`opt | [数组字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/array-literal-item) `,` [数组字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/array-literal-items)
>
> 数组字面量项 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
>
> 字典字面量 → `[` [字典字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/dictionary-literal-items) `]` | `[` `:` `]`
>
> 字典字面量项 → [字典字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/dictionary-literal-item) `,`opt | [字典字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/dictionary-literal-item)`,` [字典字面量项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/dictionary-literal-items)
>
> 字典字面量项 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
>
> 练习场字面量 → `#colorLiteral` `(` `red` `:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `,` `green` `:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `,` `blue` `:`[表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `,` `alpha` `:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
>
> 练习场字面量 → `#fileLiteral` `(` `resourceName` `:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
>
> 练习场字面量 → `#imageLiteral` `(` `resourceName` `:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
> self 表达式语法
>
> self 表达式 → `self` | [ self 方法表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/self-method-expression) | [ self 下标表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/self-subscript-expression) | [ self 构造器表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/self-initializer-expression)
>
> self 方法表达式 → `self` `.` [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> self 下标表达式 → `self` `[` [函数调用参数列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-list) `]`
>
> self 初始化表达式 → `self` `.` `init`
---
> 父类表达式语法
>
> 超类表达式 → [超类方法表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/superclass-method-expression) | [超类下标表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/superclass-subscript-expression) | [超类初始化表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/superclass-initializer-expression)
>
> 超类方法表达式 → `super` `.` [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 超类下标表达式 → `super` `[` [函数调用参数列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-list) `]`
>
> 超类初始化表达式 → `super` `.` `init`
---
> 闭包表达式语法
>
> 闭包表达式 → `{` [闭包签名](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-signature) opt [声明](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) opt `}`
>
> 闭包签名 → [闭包列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/capture-list) opt [闭包参数子句](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-parameter-clause) `throws`opt[函数结果](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-result) opt `in`
>
> 闭包签名 → [闭包列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/capture-list) `in`
>
> 闭包参数子句 → `(` `)` | `(` [闭包参数](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-parameter-list) `)` | [标识符列表](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier-list)
>
> 闭包参数列表 → [闭包参数](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-parameter) | [闭包参数](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-parameter) `,` [闭包参数列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-parameter-list)
>
> 闭包参数 → [闭包参数名称](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-parameter-name) [类型注解](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) opt
>
> 闭包参数 → [闭包参数名称](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-parameter-name) [类型注解](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) `...`
>
> 闭包参数名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 闭包列表 → `[`[闭包列表项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/capture-list-items) `]`
>
> 闭包列表项 → [闭包列表项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/capture-list-item) | [闭包列表项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/capture-list-item) `,` [闭包列表项](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/capture-list-items)
>
> 闭包列表项 → [捕获说明符](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/capture-specifier) opt [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
>
> 捕获说明符 → `weak` | `unowned` | `unowned(safe)` | `unowned(unsafe)`
> 隐式成员表达式语法
>
> 隐式成员表达式 → `.` [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
---
> 圆括号表达式语法
>
> 圆括号表达式 → `(` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
---
> 元组表达式语法
>
> 元组表达式 → `(` `)` | `(` [元组元素](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/tuple-element) `,` [元组元素列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/tuple-element-list) `)`
>
> 元组元素列表 → [元组元素](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/tuple-element) | [元组元素](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/tuple-element) `,` [元组元素列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/tuple-element-list)
>
> 元组元素 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) | [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `:` [标识符](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
---
> 通配符表达式语法
>
> 通配符表达式 → `_`
---
> key-path 表达式语法
>
> key-path 表达式 → `\` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type) opt `.` [ key-path 组件](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-components)
>
> key-path 组件 → [key-path 组件](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-component) | [key-path 组件](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-component) `.` [key-path 组件](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-components)
>
> key-path 组件 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) [ key-path 后缀](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-postfixes) opt | [ key-path 后缀](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-postfixes)
>
> key-path 后缀 → [ key-path 后缀](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-postfix) [ key-path 后缀](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/key-path-postfixes) opt
>
> key-path 后缀 → `?` | `!` | `[` [函数调用参数列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-list) `]`
> 选择器表达式语法
>
> 选择器表达式 → `#selector` `(` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
>
> 选择器表达式 → `#selector` `(` `getter:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
>
> 选择器表达式 → `#selector` `(` `setter:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
---
> key-path 字符串表达式语法
>
> key-path 字符串表达式 → `#keyPath` `(` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `)`
---
> 后缀表达式语法
>
>后缀表达式 → [基本表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/primary-expression)
>
> 后缀表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) [后缀运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/postfix-operator)
>
> 后缀表达式 → [函数调用表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-expression)
>
> 后缀表达式 → [初始化表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/initializer-expression)
>
> 后缀表达式 → [显式成员表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/explicit-member-expression)
>
> 后缀表达式 → [后缀 self 表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-self-expression)
>
> 后缀表达式 → [下标表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/subscript-expression)
>
> 后缀表达式 → [强制取值表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/forced-value-expression)
>
> 后缀表达式 → [可选链表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/optional-chaining-expression)
---
> 函数调用表达式语法
>
> 函数调用表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) [函数调用参数子句](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-clause)
>
> 函数调用表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) [函数调用参数子句](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-clause) opt [尾随闭包](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/trailing-closure)
>
> 函数调用参数子句 → `(` `)` | `(` [函数调用参数列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-list) `)`
>
> 函数调用参数列表 → [函数调用参数](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument) | [函数调用参数](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument) `,`[函数调用参数列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-list)
>
> 函数调用参数 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) | [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `:` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
>
> 函数调用参数 → [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator) | [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `:` [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
>
> 尾随闭包 → [闭包表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/closure-expression)
> 初始化表达式语法
>
> 初始化表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `.` `init`
>
> 初始化表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `.` `init` `(` [参数名称](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/argument-names) `)`
---
> 显式成员表达式语法
>
> 显式成员表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `.` [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits)
>
> 显式成员表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `.` [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) [泛型参数子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument-clause) opt
>
> 显式成员表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `.` [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `(` [参数名称](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/argument-names) `)`
>
> 参数名称 → [参数名称](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/argument-name) [参数名称](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/argument-names) opt
>
> 参数名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `:`
---
> 后缀 self 表达式语法
>
> 后缀 self 表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `.` `self`
---
> 下标表达式语法
>
> 下标表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `[` [函数调用参数列表](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/function-call-argument-list) `]`
---
> 强制取值表达式语法
>
> 强制取值表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `!`
---
> 可选链表达式语法
>
> 可选链表达式 → [后缀表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/postfix-expression) `?`
语句
-------------------------------
> 语句语法
>
> 语句 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `;`opt
>
> 语句 → [语句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration) `;`opt
>
> 语句 → [循环语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/loop-statement) `;`opt
>
> 语句 → [分支语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/branch-statement) `;`opt
>
> 语句 → [标签语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/labeled-statement) `;`opt
>
> 语句 → [控制转移语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/control-transfer-statement) `;`opt
>
> 语句 → [ defer 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/defer-statement) `;`opt
>
> 语句 → [ do 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/do-statement)`;`opt
>
> 语句 → [编译器控制语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compiler-control-statement)
>
> 语句 → [语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statement)[语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) opt
---
> 循环语句语法
>
> 循环语句 → [ for-in 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/for-in-statement)
>
> 循环语句 → [ while 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/while-statement)
>
> 循环语句 → [ repeat-while 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/repeat-while-statement)
---
> for-in 语句语法
>
> for-in 语句 → `for` `case`opt [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) `in` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) [where 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/where-clause) opt [code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
---
> while 语句语法
>
> while 语句 → `while` [条件列表](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/condition-list) [code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> 条件列表 → [条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/condition) | [条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/condition) `,` [条件列表](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/condition-list)
>
> 条件 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) | [可用性条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/availability-condition) | [case 条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/case-condition) | [任选约束条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/optional-binding-condition)
>
> case 条件 → `case` [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) [初始化](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer)
>
> 任选约束条件 → `let` [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) [初始化](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer) | `var` [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) [初始化](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer)
> repeat-while 语句语法
>
> repeat-while 语句 → `repeat` [ code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block) `while` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
---
> 分支语句语法
>
> 分支语句 → [ if 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/if-statement)
>
> 分支语句 → [ guard 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/guard-statement)
>
> 分支语句 → [ switch 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/switch-statement)
---
> if 语句语法
>
> if 语句 → `if`[条件列表](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/condition-list) [ code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block) [ else 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/else-clause) opt
>
> else 子句 → `else`[ code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block) | `else` [ if 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/if-statement)
---
> guard 语句语法
>
> guard 语句 → `guard` [条件列表](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/condition-list) `else` [ code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
---
> switch 语句语法
>
> switch 语法 → `switch` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) `{` [ switch 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/switch-cases) opt `}`
>
> switch 子句 → [ switch 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/switch-case) [ switch 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/switch-cases) opt
>
> switch 子句 → [ case 标签](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/case-label)[语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) | [ default 标签](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/default-label) [语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements)
>
> case 标签 → `case` [ case 项列表](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/case-item-list) `:`
>
> case 项列表 → [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern)[ where 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/where-clause) opt | [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) [ where 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/where-clause) opt `,` [case 项列表](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/case-item-list)
>
> default 标签 → `default :`
>
> where 子句 → `where`[ where 表达式](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/where-expression)
>
> where 表达式 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
> 标签语句语法
>
> 标签语句 → [语句标签](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statement-label) [ loop 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/loop-statement)
>
> 标签语句 → [语句标签](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statement-label) [ if 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/if-statement)
>
> 标签语句 → [语句标签](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statement-label) [ switch 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/switch-statement)
>
> 标签语句 → [语句标签](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statement-label) [ do 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/do-statement)
>
> 语句标签 → [标签名称](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/label-name) `:`
>
> 标签名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
---
> 控制转移语句语法
>
> 控制转移语句 → [ break 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/break-statement)
>
> 控制转移语句 → [ continue 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/continue-statement)
>
> 控制转移语句 → [ fallthrough 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/fallthrough-statement)
>
> 控制转移语句 → [ return 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/return-statement)
>
> 控制转移语句 → [ throw 语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/throw-statement)
---
> break 语句语法
>
> break 语句 → `break` [标签名称](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/label-name) opt
---
> continue 语句语法
>
> continue 语句 → `continue` [标签名称](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/label-name) opt
---
> fallthrough 语句语法
>
> fallthrough 语句 → `fallthrough`
> return 语句语法
>
> return 语句 → `return` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression) opt
---
> throw 语句语法
>
> throw 语句 → `throw` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
---
> defer 语句语法
>
> defer 语句 → `defer` [ code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
---
> do 语句语法
>
> do 语句 → `do`[ code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block) [ catch 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/catch-clauses) opt
>
> catch 子句 → [ catch 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/catch-clause) [ catch 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/catch-clauses) opt
>
> catch 子句 → `catch`[模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) opt [ where 子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/where-clause) opt [ code 块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
---
> 编译控制语句语法
>
> 编译控制语句 → [条件编译块](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/conditional-compilation-block)
>
> 编译控制语句 → [线路控制语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/line-control-statement)
>
> 编译控制语句 → [诊断语句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/diagnostic-statement)
> 条件编译块语法
>
> 条件编译块 → [ if 指令子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/if-directive-clause) [ elseif 指令子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/elseif-directive-clauses) opt [ else 指令子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/else-directive-clause) opt [ endif 指令子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/endif-directive)
>
> if 指令子句 → [ if 指令](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/if-directive) [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition) [声明](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) opt
>
> elseif 指令子句 → [ elseif 指令子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/elseif-directive-clause) [ elseif 指令子句](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/elseif-directive-clauses) opt
>
> elseif 指令子句 → [ elseif 指令](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/elseif-directive) [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition) [声明](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) opt
>
> else 指令子句 → [ else 指令](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/else-directive) [声明](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) opt
>
> if 指令 → `#if`
>
> elseif 指令 → `#elseif`
>
> else 指令 → `#else`
>
> endif 指令 → `#endif`
>
> 编译条件 → [平台条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/platform-condition)
>
> 编译条件 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 编译条件 → [ boolean 字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/boolean-literal)
>
> 编译条件 → `(` [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition) `)`
>
> 编译条件 → `!` [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition)
>
> 编译条件 → [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition) `&&` [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition)
>
> 编译条件 → [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition) `||` [编译条件](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compilation-condition)
>
> 平台条件 → `os` `(` [操作系统](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/operating-system) `)`
>
> 平台条件 → `arch` `(` [结构](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/architecture) `)`
>
> 平台条件 → `swift` `(` `>=` [swift 版本](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/swift-version) `)`
>
> 平台条件 → `canImport` `(` [模块名称](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/module-name) `)`
>
> 平台条件 → `targetEnvironment` `(` [运行环境](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/environment) `)`
>
> 操作系统 → `macOS` | `iOS` | `watchOS` | `tvOS`
>
> 运行环境 → `i386` |`x86_64` | `arm` | `arm64`
>
> swift 版本 → [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits) [ swift 拓展版本](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/swift-version-continuation) opt
>
> swift 拓展版本 → `.` [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits) [ swift 拓展版本](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/swift-version-continuation) opt
>
> 模块名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 运行环境 → `simulator`
> 线路控制声明语法
>
> 线路控制声明 → `#sourceLocation` `(` `file:` [file-name](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/file-name) `,` `line:` [行号](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/line-number) `)`
>
> 线路控制声明 → `#sourceLocation` `(` `)`
>
> 行号 → A decimal integer greater than zero
>
> 文件名 → [静态字符串字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/static-string-literal)
---
> 编译时诊断声明语法
>
> 编译时诊断声明 → `#error` `(` [诊断信息](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/diagnostic-message) `)`
>
> 诊断声明 → `#warning` `(` [诊断信息](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/diagnostic-message) `)`
>
> 诊断信息 → [静态字符串字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/static-string-literal)
---
> 可用性条件语法
>
> 可用性条件 → `#available` `(` [可用性参数](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/availability-arguments) `)`
>
> 可用性参数 → [可用性参数](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/availability-argument) | [可用性参数](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/availability-argument) `,` [可用性参数](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/availability-arguments)
>
> 可用性参数 → [平台名称](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/platform-name) [平台版本](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/platform-version)
>
> 可用性参数 → `*`
>
> 平台名称 → `iOS`| `iOSApplicationExtension`
>
> 平台名称 → `macOS` | `macOSApplicationExtension`
>
> 平台名称 → `watchOS`
>
> 平台名称 → `tvOS`
>
> 平台版本 → [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits)
>
> 平台版本 → [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits) `.` [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits)
>
> 平台版本 → [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits) `.` [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits) `.` [十进制数字](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/decimal-digits)
声明
---------------------------------
> 声明语法
>
> 声明 → [导入声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/import-declaration)
>
> 声明 → [常量声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/constant-declaration)
>
> 声明 → [变量声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration)
>
> 声明 → [类型别名声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/typealias-declaration)
>
> 声明 → [函数声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-declaration)
>
> 声明 → [枚举声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/enum-declaration)
>
> 声明 → [结构体声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/struct-declaration)
>
> 声明 → [类声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-declaration)
>
> 声明 → [协议声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-declaration)
>
> 声明 → [初始化器声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer-declaration)
>
> 声明 → [去初始化器声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/deinitializer-declaration)
>
> 声明 → [扩展声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/extension-declaration)
>
> 声明 → [下标声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-declaration)
>
> 声明 → [运算符声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/operator-declaration)
>
> 声明 → [优先组声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-declaration)
>
> 声明 → [声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration) [声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declarations) opt
---
> 顶级声明语法
>
> 顶级声明 → [声明](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) opt
---
> code 块语法
>
> code 块 → `{`[声明](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/statements) opt `}`
---
> 导入声明语法
>
> 导入声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `import` [导入类型](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/import-kind) opt [导入路径](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/import-path)
>
> 导入类型 → `typealias`| `struct` | `class` | `enum` | `protocol` | `let` | `var` | `func`
>
> 导入路径 → [导入路径标识符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/import-path-identifier) | [导入路径标识符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/import-path-identifier) `.` [导入路径](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/import-path)
>
> 导入路径标识符 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) | [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
---
> 常量声明语法
>
> 常量声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt `let`[模式构造器列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/pattern-initializer-list)
>
> 模式构造器列表 → [模式初始化](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/pattern-initializer) | [模式初始化](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/pattern-initializer) `,` [模式初始化列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/pattern-initializer-list)
>
> 模式初始化 → [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) [初始化](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer) opt
>
> 初始化 → `=` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
> 变量声明语法
>
> 变量声明 → [变量声明头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration-head) [模式初始化器列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/pattern-initializer-list)
>
> 变量声明 → [变量声明头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration-head) [变量名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> 变量声明 → [变量声明头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration-head) [变量名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) [ getter-setter 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-setter-block)
>
> 变量声明 → [变量声明头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration-head) [变量名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) [ getter-setter-keyword 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-setter-keyword-block)
>
> 变量声明 → [变量声明头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration-head) [变量名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-name) [构造器](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer) [ willSet-didSet 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/willSet-didSet-block)
>
> 变量声明 → [变量声明头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration-head) [变量名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) [构造器](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer) opt [ willSet-didSet 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/willSet-didSet-block)
>
> 变量声明头 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt `var`
>
> 变量名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> getter-setter 代码块 → [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> getter-setter 代码块 → `{` [ getter 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-clause) [ setter 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/setter-clause) opt `}`
>
> getter-setter 代码块 → `{` [ setter 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/setter-clause) [ getter 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-clause) `}`
>
> getter 子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/mutation-modifier) opt `get` [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> setter 子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/mutation-modifier) opt `set` [ setter 名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/setter-name) opt [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> setter 名称 → `(`[标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `)`
>
> getter-setter-keyword 代码块 → `{` [ getter-keyword 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-keyword-clause) [ setter-keyword 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/setter-keyword-clause) opt `}`
>
> getter-setter-keyword 代码块 → `{` [ setter-keyword 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/setter-keyword-clause) [ getter-keyword 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-keyword-clause) `}`
>
> getter-keyword 子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/mutation-modifier) opt`get`
>
> setter-keyword 子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/mutation-modifier) opt`set`
>
> willSet-didSet 代码块 → `{` [ willSet 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/willSet-clause) [ didSet 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/didSet-clause) opt `}`
>
> willSet-didSet 代码块 → `{` [ didSet 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/didSet-clause) [ willSet 子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/willSet-clause) opt `}`
>
> willSet 子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `willSet` [ setter 名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/setter-name) opt [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> didSet 子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `didSet` [ setter 名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/setter-name) opt [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
> 类型别名声明语法
>
> 类型别名声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt`typealias` [类型别名名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/typealias-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [类型别名名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/typealias-assignment)
>
> 类型别名名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 类型别名赋值 → `=` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
---
> 函数声明语法
>
> 函数声明 → [函数头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-head) [函数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt[函数签名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-signature) [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [函数体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-body) opt
>
> 函数头 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt `func`
>
> 函数名 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) | [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
>
> 函数签名 → [参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-clause) `throws`opt [函数结果](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-result) opt
>
> 函数签名 → [参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-clause) `rethrows` [函数结果](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-result) opt
>
> 函数结果 → `->`[特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> 函数体 → [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> 参数子句 → `(` `)` | `(` [参数列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-list) `)`
>
> 参数列表 → [参数](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter) | [参数](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter) `,` [参数列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-list)
>
> 参数 → [外部参数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/external-parameter-name) opt [内部参数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/local-parameter-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation)[默认参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/default-argument-clause) opt
>
> 参数 → [外部参数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/external-parameter-name) opt [内部参数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/local-parameter-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation)
>
> 参数 → [外部参数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/external-parameter-name) opt [内部参数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/local-parameter-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) `...`
>
> 外部参数名 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 内部参数名 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 默认参数子句 → `=` [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
> 枚举声明语法
>
> 枚举声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt [联合风格枚举](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum)
>
> 枚举声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt [原始值风格枚举](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum)
>
> 联合风格枚举 → `indirect`opt `enum` [枚举名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/enum-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt `{` [联合风格枚举成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-members) opt `}`
>
> 联合风格枚举成员 → [联合风格枚举成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-member) [联合风格枚举成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-members) opt
>
> 联合风格枚举成员 → [声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration) | [联合风格枚举用例子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-case-clause) | [编译控制语法](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compiler-control-statement)
>
> 联合风格枚举用例子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt`indirect`opt `case` [联合风格枚举用例列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-case-list)
>
> 联合风格枚举用例列表 → [联合风格枚举用例](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-case) | [联合风格枚举用例](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-case) `,`[联合风格枚举用例列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/union-style-enum-case-list)
>
> 联合风格枚举用例 → [枚举用例名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/enum-case-name) [元组类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/tuple-type) opt
>
> 枚举名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 枚举用例名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 原始值风格枚举 → `enum` [枚举名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/enum-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt[类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt `{` [原始值风格枚举成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-members) `}`
>
> 原始值风格枚举成员 → [原始值风格枚举成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-member) [原始值风格枚举成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-members) opt
>
> 原始值风格枚举成员 → [声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration) | [原始值风格枚举用例子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-case-clause) | [编译控制语法](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compiler-control-statement)
>
> 原始值风格枚举用例子句 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `case` [原始值风格枚举用例列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-case-list)
>
> 原始值风格枚举用例列表 → [原始值风格枚举用例](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-case) | [原始值风格枚举用例](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-case) `,` [原始值风格枚举用例列表](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-style-enum-case-list)
>
> 原始值风格枚举用例 → [枚举用例名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/enum-case-name) [原始值赋值](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-assignment) opt
>
> 原始值赋值 → `=` [原始值字面量](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/raw-value-literal)
>
> 原始值字面量 → [数字字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/numeric-literal) | [静态字符串字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/static-string-literal) | [布尔字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/boolean-literal)
> 结构体声明语法
>
> 结构体声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt `struct`[结构体名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/struct-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [结构体主体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/struct-body)
>
> 结构体名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 结构体主体 → `{` [结构体成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/struct-members) opt `}`
>
> 结构体成员 → [结构体成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/struct-member) [结构体成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/struct-members) opt
>
> 结构体成员 → [声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration) | [编译控制语法](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compiler-control-statement)
---
> 类声明语法
>
> 类声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt`final`opt `class` [类名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [类主体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-body)
>
> 类声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `final` [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt`class` [类名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [类主体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-body)
>
> 类名 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 类主体 → `{` [类成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-members) opt `}`
>
> 类成员 → [类成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-member) [类成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/class-members) opt
>
> 类成员 → [声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration) | [编译控制语法](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compiler-control-statement)
---
> 协议声明语法
>
> 协议声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt`protocol` [协议名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-name) [类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [协议主体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-body)
>
> 协议名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 协议主体 → `{`[协议成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-members) opt `}`
>
> 协议成员 → [协议成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-member) [协议成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-members) opt
>
> 协议成员 → [协议成员声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-member-declaration) | [编译控制语法](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compiler-control-statement)
>
> 协议成员声明 → [协议属性声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-property-declaration)
>
> 协议成员声明 → [协议方法声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-method-declaration)
>
> 协议成员声明 → [协议构造器声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-initializer-declaration)
>
> 协议成员声明 → [协议下标声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-subscript-declaration)
>
> 协议成员声明 → [协议关联类型声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/protocol-associated-type-declaration)
>
> 协议成员声明 → [类型别名声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/typealias-declaration)
> 协议属性声明语法
>
> 协议属性声明 → [变量声明头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-declaration-head) [变量名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/variable-name) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) [ getter-setter-keyword 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-setter-keyword-block)
---
> 协议方法声明语法
>
> 协议方法声明 → [函数头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-head) [函数名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-name) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [函数签名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/function-signature) [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt
---
> 协议构造器声明语法
>
> 协议构造器声明 → [构造器头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer-head) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-clause) `throws`opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt
>
> 协议构造器声明 → [构造器头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer-head) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-clause) `rethrows` [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt
---
> 协议下标声明语法
>
> 协议下标声明 → [下标头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-head) [下标结果](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-result) [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [ getter-setter-keyword 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-setter-keyword-block)
---
> 协议关联类型声明语法
>
> 协议关联类型声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt`associatedtype` [类型别名名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/typealias-name) [类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) opt[类型别名赋值](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/typealias-assignment) opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt
---
> 构造器声明语法
>
> 构造器声明 → [构造器头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer-head) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-clause) `throws`opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [构造器主体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer-body)
>
> 构造器声明 → [构造器头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer-head) [泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-clause) `rethrows` [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [构造器主体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/initializer-body)
>
> 构造器头 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt `init`
>
> 构造器头 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt `init` `?`
>
> 构造器头 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt `init` `!`
>
> 构造器主体 → [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
---
> 析构器声明语法
>
> 析构器声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt `deinit` [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
---
> 扩展声明语法
>
> 扩展声明 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier) opt `extension` [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) [类型继承子句](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-inheritance-clause) opt [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [扩展主体](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/extension-body)
>
> 扩展主体 → `{`[扩展成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/extension-members) opt `}`
>
> 扩展成员 → [扩展成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/extension-member) [扩展成员](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/extension-members) opt
>
> 扩展成员 → [声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration) | [编译控制语法](https://docs.swift.org/swift-book/ReferenceManual/Statements.html#//appleref/swift/grammar/compiler-control-statement)
---
> 下标声明语法
>
> 下标声明 → [下标头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-head) [下标结果](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-result) [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/code-block)
>
> 下标声明 → [下标头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-head) [下标结果](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-result) [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [ getter-setter 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-setter-block)
>
> 下标声明 → [下标头](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-head) [下标结果](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/subscript-result) [泛型 where 子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-where-clause) opt [ getter-setter-keyword 代码块](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/getter-setter-keyword-block)
>
> 下标头 → [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [声明修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt `subscript`[泛型形参子句](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-clause) opt [参数子句](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/parameter-clause)
>
> 下标结果 → `->` [特性列表](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
> 运算符声明语法
>
> 运算符声明 → [前缀运算符声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/prefix-operator-declaration) | [前缀运算符声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/postfix-operator-declaration) | [后缀运算符声明](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/infix-operator-declaration)
>
> 前缀运算符声明 → `prefix` `operator` [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
>
> 前缀运算符声明 → `postfix` `operator` [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator)
>
> 后缀运算符声明 → `infix` `operator` [运算符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/operator) [后缀运算符组](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/infix-operator-group) opt
>
> 后缀运算符组 → `:` [优先级组名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-name)
---
> 优先级组声明语法
>
> 优先级组声明 → `precedencegroup` [优先级组名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-name) `{`[优先级组属性](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-attributes) opt `}`
>
> 优先级组属性 → [优先级组属性](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-attribute) [优先级组属性](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-attributes) opt
>
> 优先级组属性 → [优先级组关系](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-relation)
>
> 优先级组属性 → [优先级组赋值性](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-assignment)
>
> precedence-group-attribute → [优先级组相关性](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-associativity)
>
> 优先级组关系 → `higherThan` `:` [优先级组名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-names)
>
> 优先级组关系 → `lowerThan` `:` [优先级组名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-names)
>
> 优先级组赋值性 → `assignment` `:` [布尔字面量](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/boolean-literal)
>
> 优先级组相关性 → `associativity` `:` `left`
>
> 优先级组相关性 → `associativity` `:` `right`
>
> 优先级组相关性 → `associativity` `:` `none`
>
> 优先级组名称 → [优先级组名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-name) | [优先级组名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-name) `,`[优先级组名称](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/precedence-group-names)
>
> 优先级组名称 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
> 声明修饰符语法
>
> 声明修饰符 → `class` | `convenience` | `dynamic` | `final` | `infix` | `lazy` | `optional` |`override` | `postfix` | `prefix` | `required` | `static` | `unowned` | `unowned ( safe )` | `unowned ( unsafe )` | `weak`
>
> 声明修饰符 → [访问级别修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/access-level-modifier)
>
> 声明修饰符 → [转义修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/mutation-modifier)
>
> 声明修饰符 → [声明修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifier) [声明修饰符](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/declaration-modifiers) opt
>
> 访问级别修饰符 → `private` | `private ( set )`
>
> 访问级别修饰符 → `fileprivate` | `fileprivate ( set )`
>
> 访问级别修饰符 → `internal` | `internal ( set )`
>
> 访问级别修饰符 → `public` | `public ( set )`
>
> 访问级别修饰符 → `open` | `open ( set )`
>
> 转义修饰符 → `mutating` | `nonmutating`
特性
-------------------------------
> 特性语法
>
> 特性 → `` @ `` [特性名](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attribute-name) [特性参数子句](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attribute-argument-clause) opt
>
> 特性名 → [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
>
> 特性参数子句 → `(` [平衡令牌](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/balanced-tokens) opt `)`
>
> 特性 → [特性](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attribute)[特性](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/attributes) opt
>
> 平衡令牌 → [平衡令牌](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/balanced-token) [平衡令牌](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/balanced-tokens) opt
>
> 平衡令牌 → `(`[平衡令牌](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/balanced-tokens) opt `)`
>
> 平衡令牌 → `[`[平衡令牌](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/balanced-tokens) opt `]`
>
> 平衡令牌 → `{`[平衡令牌](https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#//appleref/swift/grammar/balanced-tokens) opt `}`
>
> 平衡令牌 → 任何标识符、关键字、文字或运算符
>
> 平衡令牌 → 任何标点符号除外 `(`, `)`, `[`, `]`, `{`, 或者 `}`
模式
-----------------------------
> 模式语法
>
> 模式 → [通配符模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/wildcard-pattern)[类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) opt
>
> 模式 → [标识符模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/identifier-pattern)[类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) opt
>
> 模式 → [值绑定模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/value-binding-pattern)
>
> 模式 → [元组模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/tuple-pattern) [类型标注](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-annotation) opt
>
> 模式 → [枚举用例模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/enum-case-pattern)
>
> 模式 → [可选模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/optional-pattern)
>
> 模式 → [类型转换模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/type-casting-pattern)
>
> 模式 → [表达式模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/expression-pattern)
---
> 通配符模式语法
>
> 通配符模式 → `_`
---
> 标识符模式语法
>
> 标识符模式 → [identifier](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier)
---
> 值绑定模式语法
>
> 值绑定模式 → `var` [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) | `let` [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern)
---
> 元组模式语法
>
> 元组模式 → `(`[元组模式元素列表](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/tuple-pattern-element-list) opt `)`
>
> 元组模式元素列表 → [元组模式元素](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/tuple-pattern-element) | [元组模式元素](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/tuple-pattern-element) `,` [元组模式元素列表](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/tuple-pattern-element-list)
>
> 元组模式元素 → [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) | [标识符](https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#//appleref/swift/grammar/identifier) `:` [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern)
---
> 枚举用例模式语法
>
> 枚举用例模式 → [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) opt `.` [枚举用例名](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#//appleref/swift/grammar/enum-case-name) [元组模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/tuple-pattern) opt
---
> 可选模式语法
>
> 可选模式 → [标识符模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/identifier-pattern) `?`
> 类型转换模式语法
>
> 类型转换模式 → [ is 模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/is-pattern) | [ as 模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/as-pattern)
>
> is 模式 → `is` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
>
> as 模式 → [模式](https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#//appleref/swift/grammar/pattern) `as`[类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
---
> 表达式模式语法
>
> 表达式模式 → [表达式](https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#//appleref/swift/grammar/expression)
泛型参数
-----------------------------------------------------
> 泛型形参子句语法
>
> 泛型形参子句 → `<` [泛型形参列表](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-list) `>`
>
> 泛型形参列表 → [泛型形参](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter) | [泛型形参](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter) `,` [泛型形参列表](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-parameter-list)
>
> 泛型形参 → [类名](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-name)
>
> 泛型形参 → [类名](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-name) `:` [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier)
>
> 泛型形参 → [类名](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-name) `:` [协议合成类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/protocol-composition-type)
>
> 泛型 where 子句 → `where` [约束列表](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/requirement-list)
>
> 约束列表 → [约束](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/requirement) | [约束](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/requirement) `,` [约束列表](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/requirement-list)
>
> 约束 → [一致性约束](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/conformance-requirement) | [同类型约束](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/same-type-requirement)
>
> 一致性约束 → [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) `:` [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier)
>
> 同类型约束 → [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) `:` [协议合成类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/protocol-composition-type)
>
> 同类型约束 → [类型标识符](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type-identifier) `==` [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)
---
> 泛型实参子句语法
>
> 泛型实参子句 → `<` [泛型实参列表](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument-list) `>`
>
> 泛型实参列表 → [泛型实参](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument) | [泛型实参](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument) `,` [泛型实参列表](https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html#//appleref/swift/grammar/generic-argument-list)
>
> 泛型实参 → [类型](https://docs.swift.org/swift-book/ReferenceManual/Types.html#//appleref/swift/grammar/type)