-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttributes.html
More file actions
401 lines (370 loc) · 27.2 KB
/
Attributes.html
File metadata and controls
401 lines (370 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>The Swift Programming Language: Attributes</title>
<link rel="stylesheet" type="text/css" href="resource/style-1.1.15.css">
<meta charset="utf-8"> <script>window["_GOOG_TRANS_EXT_VER"] = "1";</script></head>
<body id="conceptual_flow_with_tasks" class="jazz">
<div id="_omniture_top">
</div>
<a name="TP40014097" title="The Swift Programming Language"></a>
<section id="valence">
<div class="content-wrapper">
<p id="hierarchial_navigation">
<span id="book_title">The Swift Programming Language</span>
</p>
<img id="shortstack" src="./resource/shortstack_2x.png">
</div>
</section>
<div class="content-wrapper">
<nav class="book-parts hideInXcode" role="navigation">
<ul class="nav-parts">
<li data-id="TP40014097-CH1-XID_27" class="part-name">Welcome to Swift
<ul class="nav-chapters">
<li class="nav-chapter nav-visited-chapter">
<a href="About Swift.html#TP40014097-CH3-XID_0" data-id="TP40014097-CH3-XID_0" class="">About Swift</a>
</li>
<li class="nav-chapter">
<a href="A Swift Tour.html#TP40014097-CH2-XID_1" data-id="TP40014097-CH2-XID_1" class="">A Swift Tour</a>
</li>
</ul>
</li><li data-id="TP40014097-CH4-XID_299" class="part-name">Language Guide
<ul class="nav-chapters">
<li class="nav-chapter">
<a href="The Basics.html#TP40014097-CH5-XID_399" data-id="TP40014097-CH5-XID_399" class="">The Basics</a>
</li>
<li class="nav-chapter">
<a href="Basic Operators.html#TP40014097-CH6-XID_70" data-id="TP40014097-CH6-XID_70" class="">Basic Operators</a>
</li>
<li class="nav-chapter">
<a href="Strings and Characters.html#TP40014097-CH7-XID_368" data-id="TP40014097-CH7-XID_368" class="">Strings and Characters</a>
</li>
<li class="nav-chapter">
<a href="Collection Types.html#TP40014097-CH8-XID_133" data-id="TP40014097-CH8-XID_133" class="">Collection Types</a>
</li>
<li class="nav-chapter">
<a href="Control Flow.html#TP40014097-CH9-XID_153" data-id="TP40014097-CH9-XID_153" class="">Control Flow</a>
</li>
<li class="nav-chapter">
<a href="Functions.html#TP40014097-CH10-XID_204" data-id="TP40014097-CH10-XID_204" class="">Functions</a>
</li>
<li class="nav-chapter">
<a href="Closures.html#TP40014097-CH11-XID_117" data-id="TP40014097-CH11-XID_117" class="">Closures</a>
</li>
<li class="nav-chapter">
<a href="Enumerations.html#TP40014097-CH12-XID_185" data-id="TP40014097-CH12-XID_185" class="">Enumerations</a>
</li>
<li class="nav-chapter">
<a href="Classes and Structures.html#TP40014097-CH13-XID_94" data-id="TP40014097-CH13-XID_94" class="">Classes and Structures</a>
</li>
<li class="nav-chapter">
<a href="Properties.html#TP40014097-CH14-XID_323" data-id="TP40014097-CH14-XID_323" class="">Properties</a>
</li>
<li class="nav-chapter">
<a href="Methods.html#TP40014097-CH15-XID_300" data-id="TP40014097-CH15-XID_300" class="">Methods</a>
</li>
<li class="nav-chapter">
<a href="Subscripts.html#TP40014097-CH16-XID_393" data-id="TP40014097-CH16-XID_393" class="">Subscripts</a>
</li>
<li class="nav-chapter">
<a href="Inheritance.html#TP40014097-CH17-XID_251" data-id="TP40014097-CH17-XID_251" class="">Inheritance</a>
</li>
<li class="nav-chapter">
<a href="Initialization.html#TP40014097-CH18-XID_266" data-id="TP40014097-CH18-XID_266" class="">Initialization</a>
</li>
<li class="nav-chapter">
<a href="Deinitialization.html#TP40014097-CH19-XID_182" data-id="TP40014097-CH19-XID_182" class="">Deinitialization</a>
</li>
<li class="nav-chapter">
<a href="Automatic Reference Counting.html#TP40014097-CH20-XID_50" data-id="TP40014097-CH20-XID_50" class="">Automatic Reference Counting</a>
</li>
<li class="nav-chapter">
<a href="Optional Chaining.html#TP40014097-CH21-XID_312" data-id="TP40014097-CH21-XID_312" class="">Optional Chaining</a>
</li>
<li class="nav-chapter">
<a href="Type Casting.html#TP40014097-CH22-XID_443" data-id="TP40014097-CH22-XID_443" class="">Type Casting</a>
</li>
<li class="nav-chapter">
<a href="Nested Types.html#TP40014097-CH23-XID_309" data-id="TP40014097-CH23-XID_309" class="">Nested Types</a>
</li>
<li class="nav-chapter">
<a href="Extensions.html#TP40014097-CH24-XID_191" data-id="TP40014097-CH24-XID_191" class="">Extensions</a>
</li>
<li class="nav-chapter">
<a href="Protocols.html#TP40014097-CH25-XID_345" data-id="TP40014097-CH25-XID_345" class="">Protocols</a>
</li>
<li class="nav-chapter">
<a href="Generics.html#TP40014097-CH26-XID_234" data-id="TP40014097-CH26-XID_234" class="">Generics</a>
</li>
<li class="nav-chapter">
<a href="Advanced Operators.html#TP40014097-CH27-XID_28" data-id="TP40014097-CH27-XID_28" class="">Advanced Operators</a>
</li>
</ul>
</li><li data-id="TP40014097-CH28-XID_912" class="part-name nav-part-active open-part">Language Reference
<ul class="nav-chapters" style="height: 299px;">
<li class="nav-chapter">
<a href="About the Language Reference.html#TP40014097-CH29-XID_453" data-id="TP40014097-CH29-XID_453" >About the Language Reference</a>
</li>
<li class="nav-chapter">
<a href="Lexical Structure.html#TP40014097-CH30-XID_794" data-id="TP40014097-CH30-XID_794" class="">Lexical Structure</a>
</li>
<li class="nav-chapter">
<a href="Types.html#TP40014097-CH31-XID_988" data-id="TP40014097-CH31-XID_988" class="">Types</a>
</li>
<li class="nav-chapter">
<a href="Expressions.html#TP40014097-CH32-XID_655" data-id="TP40014097-CH32-XID_655" class="">Expressions</a>
</li>
<li class="nav-chapter">
<a href="Statements.html#TP40014097-CH33-XID_913" data-id="TP40014097-CH33-XID_913" class="">Statements</a>
</li>
<li class="nav-chapter ">
<a href="Declarations.html#TP40014097-CH34-XID_475" data-id="TP40014097-CH34-XID_475" >Declarations</a>
</li>
<li class="nav-chapter nav-current-chapter">
<a href="Attributes.html#TP40014097-CH35-XID_460" data-id="TP40014097-CH35-XID_460" class="nav-chapter-active">Attributes</a>
</li>
<li class="nav-chapter">
<a href="Patterns.html" data-id="TP40014097-CH36-XID_878">Patterns</a>
</li>
<li class="nav-chapter">
<a href="Generic Parameters and Arguments.html#TP40014097-CH37-XID_774" data-id="TP40014097-CH37-XID_774">Generic Parameters and Arguments</a>
</li>
<li class="nav-chapter">
<a href="Summary of the Grammar.html#TP40014097-CH38-XID_1030" data-id="TP40014097-CH38-XID_1030">Summary of the Grammar</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="chapter">
<a name="TP40014097-CH35"></a><a name="TP40014097-CH35-XID_460"></a>
<div class="pixel-line"></div>
<h2 class="chapter-name chapter-name-short">Attributes</h2>
<section role="navigation" class="hideInXcode" id="mini_toc">
<div id="mini_toc_button">
<p>On This Page</p>
</div>
<ul class="list-bullet">
<li class="item">
<p class="para">
<a href="#TP40014097-CH35-XID_461">
Declaration Attributes
</a>
</p>
</li>
<li class="item">
<p class="para">
<a href="#TP40014097-CH35-XID_463">
Type Attributes
</a>
</p>
</li>
</ul>
</section>
<section class="section">
<p class="para">
<em>Attributes</em> provide more information about a declaration or type. There are two kinds of attributes in Swift, those that apply to declarations and those that apply to types. For instance, the <code class="code-voice">required</code> attribute—when applied to a designated or convenience initializer declaration of a class—indicates that every subclass must implement that initializer. And the <code class="code-voice">noreturn</code> attribute—when applied to a function or method type—indicates that the function or method doesn’t return to its caller.
</p>
<p class="para">
You specify an attribute by writing the <code class="code-voice">@</code> symbol followed by the attribute’s name and any arguments that the attribute accepts:
</p>
<span class="caption"></span>
<div class="code-outline">
<ul class="code-outline-lines">
<li><pre class="code-voice">@<em class="variable-text">attribute name</em></pre></li><li><pre class="code-voice">@<em class="variable-text">attribute name</em>(<em class="variable-text">attribute arguments</em>)</pre></li>
</ul>
</div><p class="para">
Some declaration attributes accept arguments that specify more information about the attribute and how it applies to a particular declaration. These <em>attribute arguments</em> are enclosed in parentheses, and their format is defined by the attribute they belong to.
</p>
</section>
<section class="section">
<a name="TP40014097-CH35-XID_461"></a>
<h3 tabindex="0" class="section-name">Declaration Attributes</h3>
<p class="para">
You can apply a declaration attribute to declarations only. However, you can also apply the <code class="code-voice">noreturn</code> attribute to a function or method <em>type</em>.
</p><dl class="term-definition termdef">
<dt class="term"><code class="code-voice">assignment</code></dt><dd class="definition"><p class="para">
Apply this attribute to functions that overload a compound assignment operator. Functions that overload a compound assignment operator must mark their initial input parameter as <code class="code-voice">inout</code>. For an example of how to use the <code class="code-voice">assignment</code> attribute, see <span class="x-name"><a data-id="TP40014097-CH27-XID_45" href="Advanced Operators.html#TP40014097-CH27-XID_45">Compound Assignment Operators</a></span>.
</p></dd>
</dl><dl class="term-definition termdef">
<dt class="term"><code class="code-voice">class_protocol</code></dt><dd class="definition"><p class="para">
Apply this attribute to a protocol to indicate that the protocol can be adopted by class types only.
</p><p class="para">
If you apply the <code class="code-voice">objc</code> attribute to a protocol, the <code class="code-voice">class_protocol</code> attribute is implicitly applied to that protocol; there’s no need to mark the protocol with the <code class="code-voice">class_protocol</code> attribute explicitly.
</p></dd><dt class="term"><code class="code-voice">exported</code></dt><dd class="definition"><p class="para">
Apply this attribute to an import declaration to export the imported module, submodule, or declaration from the current module. If another module imports the current module, that other module can access the items exported by the current module.
</p></dd><dt class="term"><code class="code-voice">final</code></dt><dd class="definition"><p class="para">
Apply this attribute to a class or to a property, method, or subscript member of a class. It’s applied to a class to indicate that the class can’t be subclassed. It’s applied to a property, method, or subscript of a class to indicate that that class member can’t be overridden in any subclass.
</p></dd>
</dl><dl class="term-definition termdef">
<dt class="term"><code class="code-voice">lazy</code></dt><dd class="definition"><p class="para">
Apply this attribute to a stored variable property of a class or structure to indicate that the property’s initial value is calculated and stored at most once, when the property is first accessed. For an example of how to use the <code class="code-voice">lazy</code> attribute, see <span class="x-name"><a data-id="TP40014097-CH14-XID_326" href="Properties.html#TP40014097-CH14-XID_326">Lazy Stored Properties</a></span>.
</p></dd><dt class="term"><code class="code-voice">noreturn</code></dt><dd class="definition"><p class="para">
Apply this attribute to a function or method declaration to indicate that the corresponding type of that function or method, <code class="code-voice">T</code>, is <code class="code-voice">@noreturn T</code>. You can mark a function or method type with this attribute to indicate that the function or method doesn’t return to its caller.
</p><p class="para">
You can override a function or method that is not marked with the <code class="code-voice">noreturn</code> attribute with a function or method that is. That said, you can’t override a function or method that is marked with the <code class="code-voice">noreturn</code> attribute with a function or method that is not. Similar rules apply when you implement a protocol method in a conforming type.
</p></dd><dt class="term"><code class="code-voice">NSCopying</code></dt><dd class="definition"><p class="para">
Apply this attribute to a stored variable property of a class. This attribute causes the property’s setter to be synthesized with a <em>copy</em> of the property’s value—returned by the <code class="code-voice">copyWithZone</code> method—instead of the value of the property itself. The type of the property must conform to the <code class="code-voice">NSCopying</code> protocol.
</p><p class="para">
The <code class="code-voice">NSCopying</code> attribute behaves in a way similar to the Objective-C <code class="code-voice">copy</code> property attribute.
</p></dd>
</dl><dl class="term-definition termdef">
<dt class="term"><code class="code-voice">NSManaged</code></dt><dd class="definition"><p class="para">
Apply this attribute to a stored variable property of a class that inherits from <code class="code-voice">NSManagedObject</code> to indicate that the storage and implementation of the property are provided dynamically by Core Data at runtime based on the associated entity description.
</p></dd><dt class="term"><code class="code-voice">objc</code></dt><dd class="definition"><p class="para">
Apply this attribute to any declaration that can be represented in Objective-C—for example, non-nested classes, protocols, properties and methods (including getters and setters) of classes and protocols, initializers, deinitializers, and subscripts. The <code class="code-voice">objc</code> attribute tells the compiler that a declaration is available to use in Objective-C code.
</p><p class="para">
If you apply the <code class="code-voice">objc</code> attribute to a class or protocol, it’s implicitly applied to the members of that class or protocol. The compiler also implicitly adds the <code class="code-voice">objc</code> attribute to a class that inherits from another class marked with the <code class="code-voice">objc</code> attribute. Protocols marked with the <code class="code-voice">objc</code> attribute can’t inherit from protocols that aren’t.
</p><p class="para">
The <code class="code-voice">objc</code> attribute optionally accepts a single attribute argument, which consists of an identifier. Use this attribute when you want to expose a different name to Objective-C for the entity the <code class="code-voice">objc</code> attribute applies to. You can use this argument to name classes, protocols, methods, getters, setters, and initializers. The example below exposes the getter for the <code class="code-voice">enabled</code> property of the <code class="code-voice">ExampleClass</code> to Objective-C code as <code class="code-voice">isEnabled</code> rather than just as the name of the property itself.
</p><section class="code-listing">
<span class="caption"></span>
<div class="code-sample">
<ul class="code-lines">
<li><code class="code-voice"><span class="kt">@objc</span></code></li>
<li><code class="code-voice"><span class="kt">class</span> <span class="vc">ExampleClass</span> {</code></li>
<li><code class="code-voice"> <span class="kt">var</span> <span class="vc">enabled</span>: <span class="n"></span> {</code></li>
<li><code class="code-voice"> <span class="kt">@objc</span>(<span class="vc">isEnabled</span>) <span class="kt">get</span> {</code></li>
<li><code class="code-voice"> <span class="c">// Return the appropriate value</span></code></li>
<li><code class="code-voice"> }</code></li>
<li><code class="code-voice"> }</code></li>
<li><code class="code-voice">}</code></li>
</ul>
</div>
</section></dd>
</dl><dl class="term-definition termdef">
<dt class="term"><code class="code-voice">optional</code></dt><dd class="definition"><p class="para">
Apply this attribute to a protocol’s property, method, or subscript members to indicate that a conforming type isn’t required to implement those members.
</p><p class="para">
You can apply the <code class="code-voice">optional</code> attribute only to protocols that are marked with the <code class="code-voice">objc</code> attribute. As a result, only class types can adopt and conform to a protocol that contains optional member requirements. For more information about how to use the <code class="code-voice">optional</code> attribute and for guidance about how to access optional protocol members—for example, when you’re not sure whether a conforming type implements them—see <span class="x-name"><a data-id="TP40014097-CH25-XID_365" href="Protocols.html#TP40014097-CH25-XID_365">Optional Protocol Requirements</a></span>.
</p></dd>
</dl><dl class="term-definition termdef">
<dt class="term"><code class="code-voice">required</code></dt><dd class="definition"><p class="para">
Apply this attribute to a designated or convenience initializer of a class to indicate that every subclass must implement that initializer.
</p><p class="para">
Required designated initializers must be implemented explicitly. Required convenience initializers can be either implemented explicitly or inherited when the subclass directly implements all of the superclass’s designated initializers (or when the subclass overrides the designated initializers with convenience initializers).
</p></dd>
</dl>
<section class="section">
<a name="TP40014097-CH35-XID_462"></a>
<h3 tabindex="0" class="section-name">Declaration Attributes Used by Interface Builder</h3>
<p class="para">
Interface Builder attributes are declaration attributes used by Interface Builder to synchronize with Xcode. Swift provides the following Interface Builder attributes: <code class="code-voice">IBAction</code>, <code class="code-voice">IBDesignable</code>, <code class="code-voice">IBInspectable</code>, and <code class="code-voice">IBOutlet</code>. These attributes are conceptually the same as their Objective-C counterparts.
</p><p class="para">
You apply the <code class="code-voice">IBOutlet</code> and <code class="code-voice">IBInspectable</code> attributes to property declarations of a class. You apply the <code class="code-voice">IBAction</code> attribute to method declarations of a class and the <code class="code-voice">IBDesignable</code> attribute to class declarations.
</p>
</section>
</section>
<section class="section">
<a name="TP40014097-CH35-XID_463"></a>
<h3 tabindex="0" class="section-name">Type Attributes</h3>
<p class="para">
You can apply type attributes to types only. However, you can also apply the <code class="code-voice">noreturn</code> attribute to a function or method <em>declaration</em>.
</p><dl class="term-definition termdef">
<dt class="term"><code class="code-voice">auto_closure</code></dt><dd class="definition"><p class="para">
This attribute is used to delay the evaluation of an expression by automatically wrapping that expression in a closure with no arguments. Apply this attribute to a function or method type that takes no arguments and that returns the type of the expression. For an example of how to use the <code class="code-voice">auto_closure</code> attribute, see <span class="x-name"><a data-id="TP40014097-CH31-XID_1005" href="Types.html#TP40014097-CH31-XID_1005">Function Type</a></span>.
</p></dd><dt class="term"><code class="code-voice">noreturn</code></dt><dd class="definition"><p class="para">
Apply this attribute to the type of a function or method to indicate that the function or method doesn’t return to its caller. You can also mark a function or method declaration with this attribute to indicate that the corresponding type of that function or method, <code class="code-voice">T</code>, is <code class="code-voice">@noreturn T</code>.
</p></dd>
</dl><div class="syntax-defs">
<p class="syntax-defs-name">
Grammar of an attribute
</p><div class="syntax-defs-group">
<p class="syntax-def">
<a name="//apple_ref/swift/grammar/attribute"></a>
<span class="syntax-def-name">
attribute
</span>
<span class="arrow">
→
</span><code class="literal">@</code><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/attribute-name" href="#//apple_ref/swift/grammar/attribute-name">attribute-name</a></span><span class="optional"><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/attribute-argument-clause" href="#//apple_ref/swift/grammar/attribute-argument-clause">attribute-argument-clause</a></span><sub class="subscript">opt</sub></span>
</p><p class="syntax-def">
<a name="//apple_ref/swift/grammar/attribute-name"></a>
<span class="syntax-def-name">
attribute-name
</span>
<span class="arrow">
→
</span><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/identifier" href="Lexical Structure.html#//apple_ref/swift/grammar/identifier">identifier</a></span>
</p><p class="syntax-def">
<a name="//apple_ref/swift/grammar/attribute-argument-clause"></a>
<span class="syntax-def-name">
attribute-argument-clause
</span>
<span class="arrow">
→
</span><code class="literal">(</code><span class="optional"><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/balanced-tokens" href="#//apple_ref/swift/grammar/balanced-tokens">balanced-tokens</a></span><sub class="subscript">opt</sub></span><code class="literal">)</code>
</p><p class="syntax-def">
<a name="//apple_ref/swift/grammar/attributes"></a>
<span class="syntax-def-name">
attributes
</span>
<span class="arrow">
→
</span><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/attribute" href="#//apple_ref/swift/grammar/attribute">attribute</a></span><span class="optional"><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/attributes" href="#//apple_ref/swift/grammar/attributes">attributes</a></span><sub class="subscript">opt</sub></span>
</p>
</div><div class="syntax-defs-group">
<p class="syntax-def">
<a name="//apple_ref/swift/grammar/balanced-tokens"></a>
<span class="syntax-def-name">
balanced-tokens
</span>
<span class="arrow">
→
</span><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/balanced-token" href="#//apple_ref/swift/grammar/balanced-token">balanced-token</a></span><span class="optional"><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/balanced-tokens" href="#//apple_ref/swift/grammar/balanced-tokens">balanced-tokens</a></span><sub class="subscript">opt</sub></span>
</p><p class="syntax-def">
<a name="//apple_ref/swift/grammar/balanced-token"></a>
<span class="syntax-def-name">
balanced-token
</span>
<span class="arrow">
→
</span><code class="literal">(</code><span class="optional"><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/balanced-tokens" href="#//apple_ref/swift/grammar/balanced-tokens">balanced-tokens</a></span><sub class="subscript">opt</sub></span><code class="literal">)</code>
</p><p class="syntax-def">
<a name="TP40014097-CH35-XID_471"></a>
<span class="syntax-def-name">
balanced-token
</span>
<span class="arrow">
→
</span><code class="literal">[</code><span class="optional"><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/balanced-tokens" href="#//apple_ref/swift/grammar/balanced-tokens">balanced-tokens</a></span><sub class="subscript">opt</sub></span><code class="literal">]</code>
</p><p class="syntax-def">
<a name="TP40014097-CH35-XID_472"></a>
<span class="syntax-def-name">
balanced-token
</span>
<span class="arrow">
→
</span><code class="literal">{</code><span class="optional"><span class="syntactic-cat"><a data-id="//apple_ref/swift/grammar/balanced-tokens" href="#//apple_ref/swift/grammar/balanced-tokens">balanced-tokens</a></span><sub class="subscript">opt</sub></span><code class="literal">}</code>
</p><p class="syntax-def">
<a name="TP40014097-CH35-XID_473"></a>
<span class="syntax-def-name">
balanced-token
</span>
<span class="arrow">
→
</span><span class="text-description">Any identifier, keyword, literal, or operator</span>
</p><p class="syntax-def">
<a name="TP40014097-CH35-XID_474"></a>
<span class="syntax-def-name">
balanced-token
</span>
<span class="arrow">
→
</span><span class="text-description">Any punctuation except <code class="literal">(</code>, <code class="literal">)</code>, <code class="literal">[</code>, <code class="literal">]</code>, <code class="literal">{</code>, or <code class="literal">}</code></span>
</p>
</div>
</div>
</section>
<section class="" id="next_previous">
<p class="previous-link"><a data-id="TP40014097-CH34-XID_475" href="Declarations.html#TP40014097-CH34-XID_475">Declarations</a></p>
<p class="next-link"><a data-id="TP40014097-CH36-XID_878" href="Patterns.html#TP40014097-CH36-XID_878">Patterns</a></p>
<p class="copyright">Copyright © 2014 Apple Inc. All rights reserved. <a rel="external" target="_blank" href="http://www.apple.com/legal/terms/site.html" class="link">Terms of Use</a> | <a rel="external" target="_blank" href="http://www.apple.com/privacy/" class="link">Privacy Policy</a> | Updated: 2014-06-02
</p>
</section>
</article>
</div>
<div id="big_button"></div>
<footer id="footer">
<div class="content-wrapper">
</div>
<script src="./resource/devpubs-1.1.15.js" type="text/javascript" charset="utf-8"></script> </footer> <div id="blackout"> <div id="preload"></div> </div> </body></html>