Swift 6.0 beta 日本語化計画 : Swift 6.0 beta


文法のまとめ


正式な文法をすべて読んでください。


語彙の構造


空白の文法

whitespacewhitespace-item whitespace?
whitespace-itemline-break
whitespace-iteminline-space
whitespace-itemcomment
whitespace-itemmultiline-comment
whitespace-item → U+0000, U+000B, or U+000C

line-break → U+000A
line-break → U+000D
line-break → U+000D followed by U+000A

inline-spacesinline-space inline-spaces?
inline-space → U+0009 or U+0020

comment → // comment-text line-break
multiline-comment → /* multiline-comment-text */

comment-textcomment-text-item comment-text?
comment-text-item → Any Unicode scalar value except U+000A or U+000D

multiline-comment-textmultiline-comment-text-item multiline-comment-text?
multiline-comment-text-itemmultiline-comment
multiline-comment-text-itemcomment-text-item
multiline-comment-text-item → Any Unicode scalar value except /* or */



識別子の文法

identifieridentifier-head identifier-characters?
identifier` identifier-head identifier-characters?`
identifierimplicit-parameter-name
identifierproperty-wrapper-projection
identifier-listidentifier | identifier , identifier-list

identifier-head → Upper- or lowercase letter A through Z
identifier-head → _
identifier-head → U+00A8, U+00AA, U+00AD, U+00AF, U+00B2–U+00B5, or U+00B7–U+00BA
identifier-head → U+00BC–U+00BE, U+00C0–U+00D6, U+00D8–U+00F6, or U+00F8–U+00FF
identifier-head → U+0100–U+02FF, U+0370–U+167F, U+1681–U+180D, or U+180F–U+1DBF
identifier-head → U+1E00–U+1FFF
identifier-head → U+200B–U+200D, U+202A–U+202E, U+203F–U+2040, U+2054, or U+2060–U+206F
identifier-head → U+2070–U+20CF, U+2100–U+218F, U+2460–U+24FF, or U+2776–U+2793
identifier-head → U+2C00–U+2DFF or U+2E80–U+2FFF
identifier-head → U+3004–U+3007, U+3021–U+302F, U+3031–U+303F, or U+3040–U+D7FF
identifier-head → U+F900–U+FD3D, U+FD40–U+FDCF, U+FDF0–U+FE1F, or U+FE30–U+FE44
identifier-head → U+FE47–U+FFFD
identifier-head → U+10000–U+1FFFD, U+20000–U+2FFFD, U+30000–U+3FFFD, or U+40000–U+4FFFD
identifier-head → U+50000–U+5FFFD, U+60000–U+6FFFD, U+70000–U+7FFFD, or U+80000–U+8FFFD
identifier-head → U+90000–U+9FFFD, U+A0000–U+AFFFD, U+B0000–U+BFFFD, or U+C0000–U+CFFFD
identifier-head → U+D0000–U+DFFFD or U+E0000–U+EFFFD

identifier-character → Digit 0 through 9
identifier-character → U+0300–U+036F, U+1DC0–U+1DFF, U+20D0–U+20FF, or U+FE20–U+FE2F
identifier-characteridentifier-head
identifier-charactersidentifier-character identifier-characters?

implicit-parameter-name$ decimal-digits
property-wrapper-projection$ identifier-characters


リテラルの文法

literal numeric-literal | string-literal | regular-expression-literal | boolean-literal | nil-literal
numeric-literal → - ? integer-literal | - ? floating-point-literal
boolean-literal true | false
nil-literal nil



整数リテラルの文法

integer-literalbinary-literal
integer-literaloctal-literal
integer-literaldecimal-literal
integer-literalhexadecimal-literal

binary-literal0b binary-digit binary-literal-characters ?
binary-digit → Digit 0 or 1
binary-literal-characterbinary-digit | _
binary-literal-charactersbinary-literal-character binary-literal-characters ?

octal-literal0o octal-digit octal-literal-characters ?
octal-digit → Digit 0 through 7
octal-literal-characteroctal-digit | _
octal-literal-charactersoctal-literal-character octal-literal-characters ?

decimal-literaldecimal-digit decimal-literal-characters ?
decimal-digit → Digit 0 through 9
decimal-digitsdecimal-digit decimal-digits ?
decimal-literal-characterdecimal-digit | _
decimal-literal-charactersdecimal-literal-character decimal-literal-characters ?

hexadecimal-literal0x hexadecimal-digit hexadecimal-literal-characters ?
hexadecimal-digit → Digit 0 through 9, a through f, or A through F
hexadecimal-literal-characterhexadecimal-digit | _
hexadecimal-literal-charactershexadecimal-literal-character hexadecimal-literal-characters ?



浮動小数点リテラルの文法

floating-point-literaldecimal-literal decimal-fraction ? decimal-exponent ?
floating-point-literalhexadecimal-literal hexadecimal-fraction ? hexadecimal-exponent

decimal-fraction. decimal-literal
decimal-exponentfloating-point-e sign ? decimal-literal

hexadecimal-fraction. hexadecimal-digit hexadecimal-literal-characters ?
hexadecimal-exponentfloating-point-p sign ? decimal-literal

floating-point-ee | E
floating-point-pp | P
sign+ | -



文字列リテラルの文法

string-literalstatic-string-literal | interpolated-string-literal

string-literal-opening-delimiterextended-string-literal-delimiter? "
string-literal-closing-delimiter → " extended-string-literal-delimiter?

static-string-literalstring-literal-opening-delimiter quoted-text? string-literal-closing-delimiter
static-string-literalmultiline-string-literal-opening-delimiter multiline-quoted-text? multiline-string-literal-closing-delimiter

multiline-string-literal-opening-delimiterextended-string-literal-delimiter? """
multiline-string-literal-closing-delimiter → """ extended-string-literal-delimiter
extended-string-literal-delimiter → # extended-string-literal-delimiter?

quoted-textquoted-text-item quoted-text?
quoted-text-itemescaped-character
quoted-text-item → Any Unicode scalar value except ", \, U+000A, or U+000D

multiline-quoted-textmultiline-quoted-text-item multiline-quoted-text?
multiline-quoted-text-itemescaped-character
multiline-quoted-text-item → Any Unicode scalar value except \
multiline-quoted-text-itemescaped-newline

interpolated-string-literalstring-literal-opening-delimiter interpolated-text? string-literal-closing-delimiter
interpolated-string-literalmultiline-string-literal-opening-delimiter interpolated-text ? multiline-string-literal-closing-delimiter

interpolated-textinterpolated-text-item interpolated-text?
interpolated-text-item\(expression) | quoted-text-item

multiline-interpolated-textmultiline-interpolated-text-item multiline-interpolated-text?
multiline-interpolated-text-item\(expression) | multiline-quoted-text-item

escape-sequence\ extended-string-literal-delimiter
escaped-characterescape-sequence 0 | escape-sequence \ | escape-sequence t | escape-sequence n | escape-sequence r | escape-sequence " | escape-sequence '
escaped-characterescape-sequence u { unicode-scalar-digits }
unicode-scalar-digits → Between one and eight hexadecimal digits

escaped-newlineescape-sequence inline-spaces? line-break



正規表現リテラルの文法

regular-expression-literal → regular-expression-literal-opening-delimiter regular-expression regular-expression-literal-closing-delimiter
regular-expression → Any regular expression

regular-expression-literal-opening-delimiter → extended-regular-expression-literal-delimiter? /
regular-expression-literal-closing-delimiter → / extended-regular-expression-literal-delimiter?

extended-regular-expression-literal-delimiter → # extended-regular-expression-literal-delimiter?



演算子の文法

operatoroperator-head operator-characters?
operatordot-operator-head dot-operator-characters?

operator-head/ | = | - | + | ! | * | % | < | > | & | | | ^ | ~ | ?
operator-head → U+00A1–U+00A7
operator-head → U+00A9 or U+00AB
operator-head → U+00AC or U+00AE
operator-head → U+00B0–U+00B1,
operator-head → U+00B6, U+00BB, U+00BF, U+00D7, or U+00F7
operator-head → U+2016–U+2017
operator-head → U+2020–U+2027
operator-head → U+2030–U+203E
operator-head → U+2041–U+2053
operator-head → U+2055–U+205E
operator-head → U+2190–U+23FF
operator-head → U+2500–U+2775
operator-head → U+2794–U+2BFF
operator-head → U+2E00–U+2E7F
operator-head → U+3001–U+3003
operator-head → U+3008–U+3020
operator-head → U+3030
operator-characteroperator-head
operator-character → U+0300–U+036F
operator-character → U+1DC0–U+1DFF
operator-character → U+20D0–U+20FF
operator-character → U+FE00–U+FE0F
operator-character → U+FE20–U+FE2F
operator-character → U+E0100–U+E01EF
operator-charactersoperator-character operator-characters?

dot-operator-head → .
dot-operator-character → . | operator-character
dot-operator-charactersdot-operator-character dot-operator-characters?

binary-operatoroperator
prefix-operatoroperator
postfix-operatoroperator




型の文法

typefunction-type
typearray-type
typedictionary-type
typetype-identifier
typetuple-type
typeoptional-type
typeimplicitly-unwrapped-optional-type
typeprotocol-composition-type
typeopaque-type
typemetatype-type
typeany-type
typeself-type
type → ( type )





型注釈の文法

type-annotation: attributes ? inout ? type



型識別子の文法

type-identifiertype-name generic-argument-clause? | type-name generic-argument-clause? . type-identifier
type-nameidentifier



タプル型の文法

tuple-type → ( ) | ( tuple-type-element , tuple-type-element-list )
tuple-type-element-listtuple-type-element | tuple-type-element , tuple-type-element-list
tuple-type-elementelement-name type-annotation | type
element-nameidentifier




関数型の文法

function-typeattributes? function-type-argument-clause async? throws-clause? -> type

function-type-argument-clause( )
function-type-argument-clause( function-type-argument-list ...? )

function-type-argument-listfunction-type-argument | function-type-argument , function-type-argument-list
function-type-argumentattributes? inout? type | argument-label type-annotation
argument-labelidentifier

throws-clausethrows | throws ( type )



配列型の文法

array-type → [ type ]



辞書型の文法

dictionary-type → [ type : type ]



Optional の型の文法

optional-typetype ?




暗黙に開封された optional の型の文法

implicitly-unwrapped-optional-typetype !



Protocol を構成する型の文法

protocol-composition-typetype-identifier & protocol-composition-continuation
protocol-composition-continuationtype-identifier | protocol-composition-type



不透明 (Opaque) 型の文法

opaque-typesome type



ボックス化されたプロトコル型の文法

boxed-protocol-typeany type



メタタイプ型の文法

metatype-typetype .Type | type . Protocol



Any 型の文法

any-typeAny



Self 型の文法

self-typeSelf



型の継承句の文法

type-inheritance-clause: type-inheritance-list
type-inheritance-listattribute? type-identifier | attribute? type-identifier , type-inheritance-list




式の文法

expressiontry-operator? await-operator? prefix-expression infix-expressions?\



接頭辞の式の文法

prefix-expressionprefix-operator? postfix-expression
prefix-expressionin-out-expression



in-out 式の文法

in-out-expression& identifier



try 式の文法

try-operatortry | try ? | try !



await 式の文法

await-operatorawait




挿入辞式の文法

infix-expressioninfix-operator prefix-expression
infix-expressionassignment-operator try-operator? prefix-expression
infix-expressionconditional-operator try-operator? prefix-expression
infix-expressiontype-casting-operator
infix-expressionsinfix-expression infix-expressions?



代入演算子の文法

assignment-operator=



条件演算子の文法

conditional-operator → ? expression :



型キャスト演算子の文法

type-casting-operatoris type
type-casting-operatoras type
type-casting-operatoras ? type
type-casting-operatoras ! type



一次式の文法

primary-expressionidentifier generic-argument-clause?
primary-expressionliteral-expression
primary-expressionself-expression
primary-expressionsuperclass-expression
primary-expressionconditional-expression
primary-expressionclosure-expression
primary-expressionparenthesized-expression
primary-expressiontuple-expression
primary-expressionimplicit-member-expression
primary-expressionwildcard-expression
primary-expressionmacro-expansion-expression
primary-expressionkey-path-expression
primary-expressionselector-expression
primary-expressionkey-path-string-expression



リテラル式の文法

literal-expressionliteral
literal-expressionarray-literal | dictionary-literal | playground-literal

array-literal[ array-literal-items? ]
array-literal-itemsarray-literal-item ,? | array-literal-item , array-literal-items
array-literal-itemexpression

dictionary-literal[ dictionary-literal-items ] | [:]
dictionary-literal-itemsdictionary-literal-item ,? | dictionary-literal-item , dictionary-literal-items
dictionary-literal-itemexpression : expression

playground-literal#colorLiteral ( red : expression , green : expression , blue : expression , alpha : expression )
playground-literal#fileLiteral ( resourceName : expression )
playground-literal#imageLiteral ( resourceName : expression )



Self 式の文法

self-expressionself | self-method-expression | self-subscript-expression | self-initializer-expression
self-method-expressionself . identifier
self-subscript-expressionself [ function-call-argument-list ]
self-initializer-expressionself . init



スーパークラス式の文法

superclass-expressionsuperclass-method-expression | superclass-subscript-expression | superclass-initializer-expression

superclass-method-expressionsuper . identifier
superclass-subscript-expressionsuper [ function-call-argument-list ]
superclass-initializer-expressionsuper . init



条件式の文法

conditional-expressionif-expression | switch-expression

if-expressionif condition-list { statement } if-expression-tail
if-expression-tailelse if-expression
if-expression-tailelse { statement }

switch-expressionswitch expression { switch-expression-cases }
switch-expression-casesswitch-expression-case switch-expression-cases?
switch-expression-casecase-label statement
switch-expression-casedefault-label statement



クロージャ式の文法

closure-expression{ attributes? closure-signature? statements? }

closure-signaturecapture-list? closure-parameter-clause throws? function-result? in
closure-signaturecapture-list in

closure-parameter-clause( ) | ( closure-parameter-list | identifier-list
closure-parameter-listclosure-parameter | closure-parameter , closure-parameter-list
closure-parameterclosure-parameter-name type-annotation?
closure-parameterclosure-parameter-name type-annotation ...
closure-parameter-nameidentifier

capture-list[ capture-list-items ]
capture-list-itemscapture-list-item | capture-list-item , capture-list-items
capture-list-itemcapture-specifier? identifier
capture-list-itemcapture-specifier? identifier = expression
capture-list-itemcapture-specifier? self-expression

capture-specifierweak | unowned | unowned(safe) | unowned(unsafe)



暗黙のメンバ式の文法

implicit-member-expression → . identifier
implicit-member-expression → . identifier . postfix-expression



括弧で囲まれた式の文法

parenthesized-expression( expression )



タプル式の文法

tuple-expression( ) | ( tuple-element , tuple-element-list )
tuple-element-listtuple-element | tuple-element , tuple-element-list
tuple-elementexpression | identifier : expression



ワイルドカード式の文法

wildcard-expression → _



キーパス式の文法

key-path-expression\ type? . key-path-components
key-path-componentskey-path-component | key-path-component. key-path-components
key-path-componentidentifier key-path-postfixes? | key-path-postfixes

key-path-postfixeskey-path-postfix key-path-postfixes?
key-path-postfix? | ! | self | [ function-call-argument-list ]



セレクタ式の文法

selector-expression#selector ( expression )
selector-expression#selector ( getter : expression )
selector-expression#selector ( setter : expression )



キーパス文字列式の文法

key-path-string-expression#keyPath ( expression )



接尾辞の式の文法

postfix-expressionprimary-expression
postfix-expressionpostfix-expression postfix-operator
postfix-expressionfunction-call-expression
postfix-expressioninitializer-expression
postfix-expressionexplicit-member-expression
postfix-expressionpostfix-self-expression
postfix-expressionsubscript-expression
postfix-expressionforced-value-expression
postfix-expressionoptional-chaining-expression



関数呼び出し式の文法

function-call-expressionpostfix-expression function-call-argument-clause
function-call-expressionpostfix-expression function-call-argument-clause? trailing-closure

function-call-argument-clause( ) | ( function-call-argument-list )
function-call-argument-listfunction-call-argument | function-call-argument , function-call-argument-list
function-call-argumentexpression | identifier : expression
function-call-argumentoperator | identifier : operator

trailing-closureclosure-expression labeled-trailing-closures?
labeled-trailing-closureslabeled-trailing-closure labeled-trailing-closures?
labeled-trailing-closureidentifier : closure-expression



イニシャライザ式の文法

initializer-expressionpostfix-expression. init
initializer-expressionpostfix-expression. init ( argument-names )



明示的なメンバ式の文法

explicit-member-expressionpostfix-expression . decimal-digits
explicit-member-expressionpostfix-expression . identifier generic-argument-clause?
explicit-member-expressionpostfix-expression . identifier ( argument-names )
explicit-member-expressionpostfix-expression conditional-compilation-block

argument-namesargument-name argument-names?
argument-nameidentifier :



接尾辞の self 式の文法

postfix-self-expressionpostfix-expression . self



サブスクリプト式の文法

subscript-expressionpostfix-expression [ function-call-argument-list ]



強制値の式の文法

forced-value-expressionpostfix-expression !



optional の連鎖式

optional-chaining-expressionpostfix-expression ?




文の文法

statementexpression ;?
statementdeclaration ;?
statementloop-statement ;?
statementbranch-statement ;?
statementlabeled-statement ;?
statementcontrol-transfer-statement ;?
statementdefer-statement ;?
statementdo-statement :?
statementcompiler-control-statement
statementsstatement statements?



ループ文の文法

loop-statementfor-in-statement
loop-statementwhile-statement
loop-statementrepeat-while-statement



for-in 文の文法

for-in-statementfor case? pattern in expression where-clause? code-block



while 文の文法

while-statementwhile condition-list code-block

condition-listcondition | condition , condition-list
conditionexpression | availability-condition | case-condition | optional-binding-condition

case-conditioncase pattern initializer
optional-binding-conditionlet pattern initializer? | var pattern initializer?



repeat-while 文の文法

repeat-while-statementrepeat code-block while expression



分岐文の文法

branch-statementif-statement
branch-statementguard-statement
branch-statementswitch-statement



if 文の文法

if-statementif condition-list code-block else-clause?
else-clauseelse code-block | else if-statement



guard 文の文法

guard-statementguard condition-list else code-block



switch 文の文法

switch-statementswitch expression {switch-cases? }
switch-casesswitch-case switch-cases?
switch-casecase-label statements
switch-casedefault-label statements
switch-caseconditional-switch-case

case-labelattributes? case case-item-list :
case-item-listpattern where-clause? | pattern where-clause? , case-item-list
default-labelattributes? default :

where-clausewhere where-expression
where-expressionexpression

conditional-switch-caseswitch-if-directive-clause switch-elseif-directive-clauses? switch-else-directive-clause? endif-directive
switch-if-directive-clauseif-directive compilation-condition switch-cases?
switch-elseif-directive-clauseselseif-directive-clauses switch-elseif-directive-clauses?
switch-elseif-directive-clauseelseif-directive compilation-condition switch-cases?
switch-else-directive-clauseelse-directive switch-cases?



ラベル付き文の文法

labeled-statementstatement-label loop-statement
labeled-statementstatement-label if-statement
labeled-statementstatement-label switch-statement
labeled-statementstatement-label do-statement

statement-labellabel-name :
label-nameidentifier



制御転送文の文法

control-transfer-statementbreak-statement
control-transfer-statementcontinue-statement
control-transfer-statementfallthrough-statement
control-transfer-statementreturn-statement
control-transfer-statementthrow-statement



break 文の文法

break-statementbreak label-name?



continue 文の文法

continue-statementcontinue label-name?



fallthrough 文の文法

fallthrough-statementfallthrough



return 文の文法

return-statementreturn expression?



throw 文の文法

throw-statementthrow expression



defer 文の文法

defer-statementdefer code-block



do 文の文法

do-statementdo code-block catch-clauses?
catch-clausescatch-clause catch-clauses?
catch-clausecatch catch-pattern-list? code-block
catch-pattern-listcatch-pattern | catch-pattern , catch-pattern-list
catch-patternpattern where-clause?



コンパイラ制御文の文法

compiler-control-statementconditional-compilation-block
compiler-control-statementline-control-statement
compiler-control-statementdiagnostic-statement



条件コンパイルブロックの文法

conditional-compilation-blockif-directive-clause elseif-directive-clauses? else-directive-clause? endif-directive
if-directive-clauseif-directive compilation-condition statements?
elseif-directive-clauseselseif-directive-clause elseif-directive-clauses?
elseif-directive-clauseelseif-directive compilation-condition statements?
else-directive-clauseelse-directive statements?
if-directive#if
elseif-directive#elseif
else-directive#else
endif-directive#endif

compilation-conditionplatform-condition
compilation-conditionidentifier
compilation-conditionboolean-literal
compilation-condition( compilation-condition )
compilation-condition! compilation-condition
compilation-conditioncompilation-condition && compilation-condition
compilation-conditioncompilation-condition || compilation-condition

platform-conditionos ( operating-system )
platform-conditionarch ( architecture )
platform-conditionswift ( >= swift-version ) | swift ( < swift-version )
platform-conditioncompiler ( >= swift-version ) | compiler ( < swift-version )
platform-conditioncanImport ( import-path )
platform-conditiontargetEnvironment ( environment )

operating-systemmacOS | iOS | watchOS | tvOS | Linux | Windows
architecturei386 | x86_64 | arm | arm64
swift-versiondecimal-digits swift-version-continuation?
swift-version-continuation → . decimal-digits swift-version-continuation?
environmentsimulator| macCatalyst



行制御文の文法

line-control-statement#sourceLocation ( file: file-path , line: line-number )
line-control-statement#sourceLocation ( )
line-number → A decimal integer greater than zero
file-namestatic-string-literal



利用可能条件の文法

availability-condition#available ( availability-arguments )
availability-condition#unavailable ( availability-arguments )
availability-argumentsavailability-argument | availability-argument , availability-arguments
availability-argumentplatform-name platform-version
availability-argument*

platform-nameiOS | iOSApplicationExtension
platform-namemacOS | macOSApplicationExtension
platform-namemacCatalyst | macCatalystApplicationExtension
platform-namewatchOS | watchOSApplicationExtension
platform-nametvOS | tvOSApplicationExtension
platform-namevisionOS | visionOSApplicationExtension
platform-versiondecimal-digits
platform-versiondecimal-digits . decimal-digits
platform-versiondecimal-digits . decimal-digits . decimal-digits



宣言


宣言の文法

declarationimport-declaration
declarationconstant-declaration
declarationvariable-declaration
declarationtypealias-declaration
declarationfunction-declaration
declarationenum-declaration
declarationstruct-declaration
declarationclass-declaration
declarationactor-declaration
declarationprotocol-declaration
declarationinitializer-declaration
declarationdeinitializer-declaration
declarationextension-declaration
declarationsubscript-declaration
declarationoperator-declaration
declarationprecedence-group-declaration \



トップレベルの宣言の文法

top-level-declarationstatements?



コードブロックの文法

code-block{ statements? }



import 宣言の文法

import-declarationattributes? import import-kind? import-path

import-kindtypealias | struct | class | enum | protocol | let | var | func
import-pathidentifier | identifier . import-path



定数の宣言の文法

constant-declarationattributes? declaration-modifiers? let pattern-initializer-list

pattern-initializer-listpattern-initializer | pattern-initializer , pattern-initializer-list
pattern-initializerpattern initializer?
initializer= expression



変数の宣言の文法

variable-declarationvariable-declaration-head pattern-initializer-list
variable-declarationvariable-declaration-head variable-name type-annotation code-block
variable-declarationvariable-declaration-head variable-name type-annotation getter-setter-block
variable-declarationvariable-declaration-head variable-name type-annotation getter-setter-keyword-block
variable-declarationvariable-declaration-head variable-name initializer willSet-didSet-block
variable-declarationvariable-declaration-head variable-name type-annotation initializer? willSet-didSet-block

variable-declaration-headattributes? declaration-modifiers? var
variable-nameidentifier

getter-setter-blockcode-block
getter-setter-block{ getter-clause setter-clause? }
getter-setter-block{ setter-clause getter-clause }
getter-clauseattributes? mutation-modifier? get code-block
setter-clauseattributes? mutation-modifier? set setter-name? code-block
setter-name → ( identifier )

getter-setter-keyword-block{ getter-keyword-clause setter-keyword-clause? }
getter-setter-keyword-block{ setter-keyword-clause getter-keyword-clause }
getter-keyword-clauseattributes? mutation-modifier? get
setter-keyword-clauseattributes? mutation-modifier? set

willSet-didSet-block{ willSet-clause didSet-clause? }
willSet-didSet-block{ didSet-clause willSet-clause? }
willSet-clauseattributes? willSet setter-name? code-block
didSet-clauseattributes? didSet setter-name? code-block



型エイリアス宣言の文法

typealias-declarationattributes? access-level-modifier? typealias
typealias-name generic-parameter-clause? typealias-assignment
typealias-nameidentifier
typealias-assignment= type



関数の宣言の文法

function-declarationfunction-head function-name generic-parameter-clause? function-signature generic-where-clause? function-body

function-headattributes? declaration-modifiers? func
function-nameidentifier | operator

function-signatureparameter-clause async? throws? function-result?
function-signatureparameter-clause async? rethrows function-result?
function-result-> attributes? type
function-bodycode-block

parameter-clause( ) | ( parameter-list )
parameter-listparameter | parameter , parameter-list
parameterexternal-parameter-name? local-parameter-name type-annotation default-argument-clause?
parameterexternal-parameter-name? local-parameter-name type-annotation
parameterexternal-parameter-name? local-parameter-name type-annotation ...
external-parameter-nameidentifier
local-parameter-nameidentifier
default-argument-clause → = expression



列挙型の宣言の文法

enum-declarationattributes? access-level-modifier? union-style-enum
enum-declarationattributes? access-level-modifier? raw-value-style-enum

union-style-enumindirect? enum enum-name generic-parameter-clause? type-inheritance-clause? generic-where-clause? { union-style-enum-members? }
union-style-enum-membersunion-style-enum-member union-style-enum-members?
union-style-enum-memberdeclaration | union-style-enum-case-clause | compiler-control-statement
union-style-enum-case-clauseattributes? indirect? case union-style-enum-case-list
union-style-enum-case-listunion-style-enum-case | union-style-enum-case , union-style-enum-case-list
union-style-enum-caseenum-case-name tuple-type?
enum-nameidentifier
enum-case-nameidentifier

raw-value-style-enumenum enum-name generic-parameter-clause? type-inheritance-clause generic-where-clause? { raw-value-style-enum-members }
raw-value-style-enum-membersraw-value-style-enum-member raw-value-style-enum-members?
raw-value-style-enum-memberdeclaration | raw-value-style-enum-case-clause | compiler-control-statement
raw-value-style-enum-case-clauseattributes? case raw-value-style-enum-case-list
raw-value-style-enum-case-listraw-value-style-enum-case | raw-value-style-enum-case , raw-value-style-enum-case-list
raw-value-style-enum-caseenum-case-name raw-value-assignment?
raw-value-assignment= raw-value-literal
raw-value-literalnumeric-literal | static-string-literal | boolean-literal


構造体の宣言の文法

struct-declarationattributes? access-level-modifier? struct struct-name generic-parameter-clause? type-inheritance-clause? generic-where-clause? struct-body
struct-nameidentifier
struct-body{ struct-members? }

struct-membersstruct-member struct-members?
struct-memberdeclarations | compiler-control-statement



クラス宣言の文法

class-declarationattributes? access-level-modifier? final? class class-name generic-parameter-clause? type-inheritance-clause? generic-where-clause? class-body
class-declarationattributes? final access-level-modifier? class class-name generic-parameter-clause? type-inheritance-clause? generic-where-clause? class-body
class-nameidentifier
class-body{ class-members? }

class-membersclass-member class-members?
class-memberdeclaration | compiler-control-statement



アクターの宣言の文法

actor-declaration → attributes? access-level-modifier? actor actor-name generic-parameter-clause? type-inheritance-clause? generic-where-clause? actor-body
actor-name → identifier
actor-body → { actor-members? }

actor-members → actor-member actor-members?
actor-member → declaration | compiler-control-statement



プロトコル宣言の文法

protocol-declarationattributes? access-level-modifier? protocol protocol-name type-inheritance-clause? generic-where-clause? protocol-body
protocol-nameidentifier
protocol-body{ protocol-members? }

protocol-membersprotocol-member protocol-members?
protocol-memberprotocol-member-declaration | compiler-control-statement

protocol-member-declarationprotocol-property-declaration
protocol-member-declarationprotocol-method-declaration
protocol-member-declarationprotocol-initializer-declaration
protocol-member-declarationprotocol-subscript-declaration
protocol-member-declarationprotocol-associated-type-declaration
protocol-member-declarationtypealias-declaration



プロトコルプロパティ宣言の文法

protocol-property-declarationvariable-declaration-head variable-name type-annotation getter-setter-keyword-block



プロトコルメソッド宣言の文法

protocol-method-declarationfunction-head function-name generic-parameter-clause? function-signature generic-where-clause?



プロトコルイニシャライザ宣言の文法

protocol-initializer-declarationinitializer-head generic-parameter-clause? parameter-clause throws-clause? generic-where-clause?
protocol-initializer-declarationinitializer-head generic-parameter-clause? parameter-clause rethrows generic-where-clause?



プロトコルサブスクリプト宣言の文法

protocol-subscript-declarationsubscript-head subscript-result generic-where-clause? getter-setter-keyword-block



プロトコルに関連した型の宣言の文法

protocol-associated-type-declarationattributes? access-level-modifier? associatedtype typealias-name type-inheritance-clause? typealias-assignment? generic-where-clause?



イニシャライザ宣言の文法

initializer-declarationinitializer-head generic-parameter-clause? parameter-clause async? throws-clause? generic-where-clause? initializer-body
initializer-declarationinitializer-head generic-parameter-clause? parameter-clause async? rethrows generic-where-clause? initializer-body
initializer-headattributes? declaration-modifiers? init
initializer-headattributes? declaration-modifiers? init ?
initializer-headattributes? declaration-modifiers? init !
initializer-bodycode-block



デイニシャライザ宣言の文法

deinitializer-declarationattributes? deinit code-block



機能拡張の宣言の文法

extension-declarationattributes? access-level-modifier? extension type-identifier type-inheritance-clause? generic-where-clause? extension-body
extension-body{ extension-members? }

extension-membersextension-member extension-members?
extension-memberdeclaration | compiler-control-statement



サブスクリプト宣言の文法

subscript-declarationsubscript-head subscript-result generic-where-clause? code-block
subscript-declarationsubscript-head subscript-result generic-where-clause? getter-setter-block
subscript-declarationsubscript-head subscript-result generic-where-clause? getter-setter-keyword-block
subscript-headattributes? declaration-modifiers? subscript generic-parameter-clause? parameter-clause
subscript-result-> attributes? type



マクロ宣言の文法

macro-declarationmacro-head identifier generic-parameter-clause? macro-signature macro-definition? generic-where-clause
macro-headattributes? declaration-modifiers? macro
macro-signatureparameter-clause macro-function-signature-result?
macro-function-signature-result-> type
macro-definition= expression



演算子の宣言の文法

operator-declarationprefix-operator-declaration | postfix-operator-declaration | infix-operator-declaration

prefix-operator-declarationprefix operator operator
postfix-operator-declarationpostfix operator operator
infix-operator-declarationinfix operator operator infix-operator-grou?

infix-operator-group: precedence-group-name



優先順位グループ宣言の文法

precedence-group-declarationprecedencegroup precedence-group-name { precedence-group-attributes? }
precedence-group-attributesprecedence-group-attribute precedence-group-attributes?
precedence-group-attributeprecedence-group-relation
precedence-group-attributeprecedence-group-assignment
precedence-group-attributeprecedence-group-associativity

precedence-group-relationhigherThan : precedence-group-names
precedence-group-relationlowerThan : precedence-group-names

precedence-group-assignmentassignment : boolean-literal

precedence-group-associativityassociativity : left
precedence-group-associativityassociativity : right
precedence-group-associativityassociativity : none
precedence-group-namesprecedence-group-name | precedence-group-name , precedence-group-names
precedence-group-nameidentifier



宣言修飾子の文法

declaration-modifierclass | convenience | dynamic | final | infix | lazy | optional | override | postfix | prefix | required | static | unowned | unowned ( safe ) | unowned ( unsafe ) | weak
declaration-modifieraccess-level-modifier
declaration-modifiermutation-modifier
declaration-modifiersdeclaration-modifier declaration-modifiers?

access-level-modifierprivate | private ( set )
access-level-modifierfileprivate | fileprivate ( set )
access-level-modifierinternal | internal ( set )
access-level-modifierpackage | package ( set )
access-level-modifierpublic | public ( set )
access-level-modifieropen | open ( set )

mutation-modifiermutating | nonmutating

actor-isolation-modifiernonisolated


属性


属性の文法

attribute@ attribute-name attribute-argument-clause?
attribute-nameidentifier
attribute-argument-clause( balanced-tokens? )
attributesattribute attributes?

balanced-tokensbalanced-token balanced-tokens?
balanced-token( balanced-tokens? )
balanced-token[ balanced-tokens? ]
balanced-token{ balanced-tokens? }
balanced-token → Any identifier, keyword, literal, or operator
balanced-token → Any punctuation except (, ) , [, ], {, or }


パターン


パターンの文法

patternwildcard-pattern type-annotation?
patternidentifier-pattern type-annotation?
patternvalue-binding-pattern
patterntuple-pattern type-annotation?
patternenum-case-pattern
patternoptional-pattern
patterntype-casting-pattern
patternexpression-pattern



ワイルドカードパターンの文法

wildcard-pattern_



識別子パターンの文法

identifier-patternidentifier



値結合パターンの文法

value-binding-patternvar pattern | let pattern



タプルパターンの文法

tuple-pattern( tuple-pattern-element-list? )
tuple-pattern-element-listtuple-pattern-element | tuple-pattern-element , tuple-pattern-element-list
tuple-pattern-elementpattern | identifier : pattern



列挙型 case パターンの文法

enum-case-patterntype-identifier? . enum-case-name tuple-pattern?



Optional パターンの文法

optional-patternidentifier-pattern ?



型キャストパターンの文法

type-casting-patternis-pattern | as-pattern
is-patternis type
as-patternpattern as type



式のパターンの文法

expression-patternexpression



汎用パラメータと引数



汎用パラメータ句の文法

generic-parameter-clause< generic-parameter-list >
generic-parameter-listgeneric-parameter | generic-parameter , generic-parameter-list
generic-parametertype-name
generic-parametertype-name : type-identifier
generic-parametertype-name : protocol-composition-type

generic-where-clausewhere requirement-list
requirement-listrequirement | requirement , requirement-list
requirementconformance-requirement | same-type-requirement

conformance-requirementtype-identifier : type-identifier
conformance-requirementtype-identifier : protocol-composition-type
same-type-requirementtype-identifier == type



汎用引数句の文法

generic-argument-clause< generic-argument-list >
generic-argument-listgeneric-argument | generic-argument , generic-argument-list
generic-argumenttype



前:汎用パラメータと引数 後:マニュアルの変更履歴

<BETA SOFTWARE>
このドキュメントには、開発中の API または技術に関する予備的な情報が含まれています。この情報は変更されることがあり、このドキュメントに従って実装されたソフトウェアは、最終的なオペレーティングシステムソフトウェアでテストする必要があります。

Apple の Beta ソフトウエアについての詳細


















トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ