1. Trang chủ
  2. » Công Nghệ Thông Tin

The swift programming language for iOSOS

359 509 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 359
Dung lượng 2,03 MB

Nội dung

The Swift Programming Language for iOS&OS X Apps muxuezi The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps .1 About Swift A Swift Tour Simple Values Control Flow Functions and Closures Objects and Classes Enumerations and Structures 11 Protocols and Extensions .14 Generics 15 The Basics 16 Constants and Variables 17 Declaring Constants and Variables .17 Type Annotations 18 Naming Constants and Variables 19 Printing Constants and Variables 19 Comments 20 Semicolons 21 Integers 21 Integer Bounds 21 Int 21 UInt 21 Floating-Point Numbers 22 Type Safety and Type Inference 22 Numeric Literals 23 Numeric Type Conversion 24 Integer Conversion 24 Integer and Floating-Point Conversion 25 Type Aliases 26 Booleans 26 Tuples 27 Optionals .28 If Statements and Forced Unwrapping 29 Optional Binding 30 nil 30 Implicitly Unwrapped Optionals 31 Assertions 32 Debugging with Assertions 32 When to Use Assertions 33 Basic Operators 33 Terminology 34 Assignment Operator .34 Arithmetic Operators .35 Remainder Operator 36 Floating-Point Remainder Calculations 37 Increment and Decrement Operators .37 Unary Minus Operator 38 Unary Plus Operator 38 i The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps Compound Assignment Operators 38 Comparison Operators 39 Ternary Conditional Operator .39 Range Operators 40 Closed Range Operator 40 Half-Closed Range Operator 41 Logical Operators 41 Logical NOT Operator 41 Logical AND Operator 42 Logical OR Operator .42 Combining Logical Operators .43 Explicit Parentheses 43 Strings and Characters 44 String Literals 44 Initializing an Empty String 45 String Mutability 45 Strings Are Value Types .46 Working with Characters .46 Counting Characters 47 Concatenating Strings and Characters 47 String Interpolation 48 Comparing Strings 48 String Equality .49 Prefix and Suffix Equality .49 Uppercase and Lowercase Strings 50 Unicode 50 Unicode Terminology 50 Unicode Representations of Strings 51 UTF-8 51 UTF-16 51 Unicode Scalars .52 Collection Types 52 Arrays 53 Array Type Shorthand Syntax .53 Array Literals 53 Accessing and Modifying an Array .54 Iterating Over an Array 56 Creating and Initializing an Array 57 Dictionaries 57 Dictionary Literals 58 Accessing and Modifying a Dictionary 59 Iterating Over a Dictionary 60 Creating an Empty Dictionary .61 Mutability of Collections .62 Control Flow 62 For Loops 63 For-In .63 ii The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps For-Condition-Increment .65 While Loops 66 While .66 Do-While .68 Conditional Statements 69 If 69 Switch 70 No Implicit Fallthrough 71 Range Matching 72 Tuples 73 Value Bindings 74 Where 75 Control Transfer Statements 76 Continue 77 Break .77 Break in a Loop Statement 77 Break in a Switch Statement 78 Fallthrough 79 Labeled Statements 80 Functions 82 Defining and Calling Functions 83 Function Parameters and Return Values .84 Multiple Input Parameters .84 Functions Without Parameters 84 Functions Without Return Values 84 Functions with Multiple Return Values 85 Function Parameter Names 86 External Parameter Names 86 Shorthand External Parameter Names 88 Default Parameter Values 88 External Names for Parameters with Default Values 89 Variadic Parameters 89 Constant and Variable Parameters 90 In-Out Parameters 91 Function Types 92 Using Function Types 93 Function Types as Parameter Types 93 Function Types as Return Types 94 Nested Functions 95 Closures .96 Closure Expressions 96 The Sort Function 97 Closure Expression Syntax 98 Inferring Type From Context 98 Implicit Returns from Single-Expression Closures .99 Shorthand Argument Names 99 Operator Functions 99 iii The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps Trailing Closures 99 Capturing Values 102 Closures Are Reference Types 104 Enumerations .104 Enumeration Syntax 105 Matching Enumeration Values with a Switch Statement 106 Associated Values .106 Raw Values 108 Classes and Structures 110 Comparing Classes and Structures 110 Definition Syntax 111 Class and Structure Instances 112 Accessing Properties 112 Memberwise Initializers for Structure Types 113 Structures and Enumerations Are Value Types 113 Classes Are Reference Types 114 Identity Operators 115 Pointers 116 Choosing Between Classes and Structures 116 Assignment and Copy Behavior for Collection Types 117 Assignment and Copy Behavior for Dictionaries 117 Assignment and Copy Behavior for Arrays 118 Ensuring That an Array Is Unique 119 Checking Whether Two Arrays Share the Same Elements 119 Forcing a Copy of an Array 120 Properties 121 Stored Properties 121 Stored Properties of Constant Structure Instances 122 Lazy Stored Properties 122 Stored Properties and Instance Variables 123 Computed Properties 124 Shorthand Setter Declaration .125 Read-Only Computed Properties 126 Property Observers 126 Global and Local Variables 128 Type Properties 128 Type Property Syntax 129 Querying and Setting Type Properties 130 Methods .132 Instance Methods 132 Local and External Parameter Names for Methods .133 Modifying External Parameter Name Behavior for Methods .134 The self Property 134 Modifying Value Types from Within Instance Methods 135 Assigning to self Within a Mutating Method 136 Type Methods 137 Subscripts 139 iv The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps Subscript Syntax 140 Subscript Usage 141 Subscript Options 141 Inheritance 143 Defining a Base Class 144 Subclassing 145 Overriding 146 Accessing Superclass Methods, Properties, and Subscripts 147 Overriding Methods 147 Overriding Properties 148 Overriding Property Getters and Setters .148 Overriding Property Observers 149 Preventing Overrides 150 Initialization .150 Setting Initial Values for Stored Properties 151 Initializers 151 Default Property Values 151 Customizing Initialization 152 Initialization Parameters 152 Local and External Parameter Names 153 Optional Property Types .153 Modifying Constant Properties During Initialization 154 Default Initializers .155 Memberwise Initializers for Structure Types 155 Initializer Delegation for Value Types 156 Class Inheritance and Initialization .158 Designated Initializers and Convenience Initializers 158 Initializer Chaining 158 Two-Phase Initialization 160 Initializer Inheritance and Overriding 163 Automatic Initializer Inheritance 163 Syntax for Designated and Convenience Initializers 164 Designated and Convenience Initializers in Action 164 Setting a Default Property Value with a Closure or Function .168 Deinitialization 170 How Deinitialization Works 170 Deinitializers in Action .170 Automatic Reference Counting 172 How ARC Works 173 ARC in Action .173 Strong Reference Cycles Between Class Instances .174 Resolving Strong Reference Cycles Between Class Instances 177 Weak References 177 Unowned References 179 Unowned References and Implicitly Unwrapped Optional Properties .182 Strong Reference Cycles for Closures 183 Resolving Strong Reference Cycles for Closures .186 v The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps Defining a Capture List .186 Weak and Unowned References 186 Optional Chaining 188 Optional Chaining as an Alternative to Forced Unwrapping 188 Defining Model Classes for Optional Chaining 190 Calling Properties Through Optional Chaining 191 Calling Methods Through Optional Chaining .192 Calling Subscripts Through Optional Chaining 192 Linking Multiple Levels of Chaining 193 Chaining on Methods With Optional Return Values 194 Type Casting 195 Defining a Class Hierarchy for Type Casting .195 Checking Type 197 Downcasting 197 Type Casting for Any and AnyObject 198 AnyObject 199 Any 200 Nested Types 201 Nested Types in Action .201 Referring to Nested Types 203 Extensions 203 Extension Syntax 204 Computed Properties 204 Initializers 205 Methods .206 Mutating Instance Methods 207 Subscripts 207 Nested Types .208 Protocols 209 Protocol Syntax 210 Property Requirements 210 Method Requirements 212 Mutating Method Requirements 213 Protocols as Types .214 Delegation 215 Adding Protocol Conformance with an Extension 218 Declaring Protocol Adoption with an Extension 219 Collections of Protocol Types .219 Protocol Inheritance 220 Protocol Composition 221 Checking for Protocol Conformance 222 Optional Protocol Requirements 224 Generics .227 The Problem That Generics Solve .227 Generic Functions 228 Type Parameters 229 Naming Type Parameters 230 vi The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps Generic Types 230 Type Constraints 233 Type Constraint Syntax .233 Type Constraints in Action 234 Associated Types 235 Associated Types in Action 235 Extending an Existing Type to Specify an Associated Type 238 Where Clauses .238 Advanced Operators 240 Bitwise Operators 240 Bitwise NOT Operator 241 Bitwise AND Operator 241 Bitwise OR Operator 242 Bitwise XOR Operator 242 Bitwise Left and Right Shift Operators .243 Shifting Behavior for Unsigned Integers .243 Shifting Behavior for Signed Integers 245 Overflow Operators .246 Value Overflow 247 Value Underflow 247 Division by Zero 249 Precedence and Associativity 249 Operator Functions 250 Prefix and Postfix Operators .251 Compound Assignment Operators 252 Equivalence Operators 252 Custom Operators 253 Precedence and Associativity for Custom Infix Operators 254 About the Language Reference 254 How to Read the Grammar 255 Lexical Structure 255 Whitespace and Comments 256 Identifiers .256 Keywords .257 Literals 258 Integer Literals 258 Floating-Point Literals 259 String Literals 260 Operators .261 Types 262 Type Annotation 263 Type Identifier .264 Tuple Type 264 Function Type 265 Array Type 266 Optional Type 267 Implicitly Unwrapped Optional Type 267 vii The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps Protocol Composition Type 268 Metatype Type .269 Type Inheritance Clause 269 Type Inference .270 Expressions 270 Prefix Expressions .271 Binary Expressions 272 Assignment Operator 273 Ternary Conditional Operator .274 Type-Casting Operators 274 Primary Expressions 275 Literal Expression 275 Self Expression 277 Superclass Expression 277 Closure Expression 278 Implicit Member Expression .279 Parenthesized Expression 280 Wildcard Expression 280 Postfix Expressions .280 Function Call Expression 281 Initializer Expression 282 Explicit Member Expression .282 Postfix Self Expression .283 Dynamic Type Expression 283 Subscript Expression 284 Forced-Value Expression 284 Optional-Chaining Expression 285 Statements 285 Loop Statements 286 For Statement 286 For-In Statement 287 While Statement 288 Do-While Statement 288 Branch Statements .289 If Statement 289 Switch Statement 290 Switch Statements Must Be Exhaustive 291 Execution Does Not Fall Through Cases Implicitly 291 Labeled Statement .292 Control Transfer Statements 292 Break Statement 293 Continue Statement .293 Fallthrough Statement 294 Return Statement 294 Declarations .294 Module Scope 296 Code Blocks 296 viii The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps Import Declaration 296 Constant Declaration 297 Variable Declaration 298 Stored Variables and Stored Variable Properties 298 Computed Variables and Computed Properties 299 Stored Variable Observers and Property Observers 299 Class and Static Variable Properties 300 Type Alias Declaration 301 Function Declaration 302 Parameter Names 302 Special Kinds of Parameters 303 Special Kinds of Methods 304 Curried Functions and Methods 304 Enumeration Declaration .305 Enumerations with Cases of Any Type .305 Enumerations with Raw Cases Values 306 Accessing Enumeration Cases .306 Structure Declaration 307 Class Declaration 308 Protocol Declaration 309 Protocol Property Declaration .311 Protocol Method Declaration 311 Protocol Initializer Declaration 312 Protocol Subscript Declaration 312 Protocol Associated Type Declaration 312 Initializer Declaration 313 Deinitializer Declaration .314 Extension Declaration 314 Subscript Declaration 315 Operator Declaration 316 Attributes 318 Declaration Attributes 318 Declaration Attributes Used by Interface Builder .320 Type Attributes 320 Patterns .321 Wildcard Pattern 322 Identifier Pattern 322 Value-Binding Pattern 323 Tuple Pattern .323 Enumeration Case Pattern 324 Type-Casting Patterns 324 Expression Pattern .325 Generic Parameters and Arguments 326 Generic Parameter Clause 326 Where Clauses .327 Generic Argument Clause 328 Summary of the Grammar 329 ix The Swift Programming Language for iOS&OS X Apps variable-declaration â variable-declaration-headÂ−variable-nameÂ−type-annotationÂ−initializerÂ−optÂ−willSet-didSet-blockÂ− variable-declaration-head â variable-name â attributesÂ−optÂ−declaration-specifiersÂ−optÂ−varÂ− identifierÂ− getter-setter-block â {Â−getter-clauseÂ−setter-clauseÂ−optÂ−}Â− getter-setter-block â {Â−setter-clauseÂ−getter-clauseÂ−}Â− getter-clause â attributesÂ−optÂ−getÂ−code-blockÂ− setter-clause â attributesÂ−optÂ−setÂ−setter-nameÂ−optÂ−code-blockÂ− setter-name â (Â−identifierÂ−)Â− getter-setter-keyword-block â {Â−getter-keyword-clauseÂ−setter-keyword-clauseÂ−optÂ−}Â− getter-setter-keyword-block â {Â−setter-keyword-clauseÂ−getter-keyword-clauseÂ−}Â− getter-keyword-clause â attributesÂ−optÂ−getÂ− setter-keyword-clause â attributesÂ−optÂ−setÂ− willSet-didSet-block â {Â−willSet-clauseÂ−didSet-clauseÂ−optÂ−}Â− willSet-didSet-block â {Â−didSet-clauseÂ−willSet-clauseÂ−}Â− willSet-clause â attributesÂ−optÂ−willSetÂ−setter-nameÂ−optÂ−code-blockÂ− didSet-clause â attributesÂ−optÂ−didSetÂ−setter-nameÂ−optÂ−code-blockÂ− Grammar of a type alias declaration typealias-declaration â typealias-headÂ−typealias-assignmentÂ− typealias-head â typealiasÂ−typealias-nameÂ− typealias-name â identifierÂ− typealias-assignment â =Â−typeÂ− Grammar of a function declaration function-declaration â function-headÂ−function-nameÂ−generic-parameter-clauseÂ−optÂ−function-signatureÂ−function-bodyÂ− function-head â attributesÂ−optÂ−declaration-specifiersÂ−optÂ−funcÂ− function-name â identifierÂ− operatorÂ− Declarations 334 The Swift Programming Language for iOS&OS X Apps function-signature â parameter-clausesÂ−function-resultÂ−optÂ− function-result â ->Â−attributesÂ−optÂ−typeÂ− function-body â code-blockÂ− parameter-clauses â parameter-clauseÂ−parameter-clausesÂ−optÂ− parameter-clause â (Â−)Â− (Â−parameter-listÂ− Â−optÂ−)Â− parameter-list â parameterÂ− parameterÂ−,Â−parameter-listÂ− parameter â inoutÂ−optÂ−letÂ−optÂ−#Â−optÂ−parameter-nameÂ−local-parameter-nameÂ−optÂ−type-annotationÂ−default-argu parameter â inoutÂ−optÂ−varÂ−#Â−optÂ−parameter-nameÂ−local-parameter-nameÂ−optÂ−type-annotationÂ−default-argument parameter â attributesÂ−optÂ−typeÂ− parameter-name â identifierÂ− _Â− local-parameter-name â identifierÂ− _Â− default-argument-clause â =Â−expressionÂ− Grammar of an enumeration declaration enum-declaration â attributesÂ−optÂ−union-style-enumÂ− attributesÂ−optÂ−raw-value-style-enumÂ− union-style-enum â enum-nameÂ−generic-parameter-clauseÂ−optÂ−{Â−union-style-enum-membersÂ−optÂ−}Â− union-style-enum-members â union-style-enum-member â union-style-enum-memberÂ−union-style-enum-membersÂ−optÂ− declarationÂ− union-style-enum-case-clauseÂ− union-style-enum-case-clause â attributesÂ−optÂ−caseÂ−union-style-enum-case-listÂ− union-style-enum-case-list â union-style-enum-caseÂ− union-style-enum-caseÂ−,Â−union-style-enum-case-listÂ− union-style-enum-case â enum-name â enum-case-nameÂ−tuple-typeÂ−optÂ− identifierÂ− enum-case-name â identifierÂ− raw-value-style-enum â enum-nameÂ−generic-parameter-clauseÂ−optÂ−:Â−type-identifierÂ−{Â−raw-value-style-enum-membersÂ−optÂ−}Â Declarations 335 The Swift Programming Language for iOS&OS X Apps raw-value-style-enum-members â raw-value-style-enum-memberÂ−raw-value-style-enum-membersÂ−optÂ− raw-value-style-enum-member â declarationÂ− raw-value-style-enum-case-clauseÂ− raw-value-style-enum-case-clause â attributesÂ−optÂ−caseÂ−raw-value-style-enum-case-listÂ− raw-value-style-enum-case-list â raw-value-style-enum-caseÂ− raw-value-style-enum-caseÂ−,Â−raw-value-style-enum-case-listÂ− raw-value-style-enum-case â raw-value-assignment â enum-case-nameÂ−raw-value-assignmentÂ−optÂ− =Â−literalÂ− Grammar of a structure declaration struct-declaration â attributesÂ−optÂ−structÂ−struct-nameÂ−generic-parameter-clauseÂ−optÂ−type-inheritance-clauseÂ−optÂ−struct-bo struct-name â identifierÂ− struct-body â {Â−declarationsÂ−optÂ−}Â− Grammar of a class declaration class-declaration â attributesÂ−optÂ−classÂ−class-nameÂ−generic-parameter-clauseÂ−optÂ−type-inheritance-clauseÂ−optÂ−class-body class-name â identifierÂ− class-body â {Â−declarationsÂ−optÂ−}Â− Grammar of a protocol declaration protocol-declaration â attributesÂ−optÂ−protocolÂ−protocol-nameÂ−type-inheritance-clauseÂ−optÂ−protocol-bodyÂ− protocol-name â identifierÂ− protocol-body â {Â−protocol-member-declarationsÂ−optÂ−}Â− protocol-member-declaration â protocol-property-declarationÂ− protocol-member-declaration â protocol-method-declarationÂ− protocol-member-declaration â protocol-initializer-declarationÂ− protocol-member-declaration â protocol-subscript-declarationÂ− protocol-member-declaration â protocol-associated-type-declarationÂ− Declarations 336 The Swift Programming Language for iOS&OS X Apps protocol-member-declarations â protocol-member-declarationÂ−protocol-member-declarationsÂ−optÂ− Grammar of a protocol property declaration protocol-property-declaration â variable-declaration-headÂ−variable-nameÂ−type-annotationÂ−getter-setter-keyword-blockÂ− Grammar of a protocol method declaration protocol-method-declaration â function-headÂ−function-nameÂ−generic-parameter-clauseÂ−optÂ−function-signatureÂ− Grammar of a protocol initializer declaration protocol-initializer-declaration â initializer-headÂ−generic-parameter-clauseÂ−optÂ−parameter-clauseÂ− Grammar of a protocol subscript declaration protocol-subscript-declaration â subscript-headÂ−subscript-resultÂ−getter-setter-keyword-blockÂ− Grammar of a protocol associated type declaration protocol-associated-type-declaration â typealias-headÂ−type-inheritance-clauseÂ−optÂ−typealias-assignmentÂ−optÂ− Grammar of an initializer declaration initializer-declaration â initializer-headÂ−generic-parameter-clauseÂ−optÂ−parameter-clauseÂ−initializer-bodyÂ− initializer-head â attributesÂ−optÂ−convenienceÂ−optÂ−initÂ− initializer-body â code-blockÂ− Grammar of a deinitializer declaration deinitializer-declaration â attributesÂ−optÂ−deinitÂ−code-blockÂ− Grammar of an extension declaration extension-declaration â extensionÂ−type-identifierÂ−type-inheritance-clauseÂ−optÂ−extension-bodyÂ− extension-body â {Â−declarationsÂ−optÂ−}Â− Grammar of a subscript declaration subscript-declaration â subscript-headÂ−subscript-resultÂ−code-blockÂ− subscript-declaration â subscript-headÂ−subscript-resultÂ−getter-setter-blockÂ− Declarations 337 The Swift Programming Language for iOS&OS X Apps subscript-declaration â subscript-head â subscript-headÂ−subscript-resultÂ−getter-setter-keyword-blockÂ− attributesÂ−optÂ−subscriptÂ−parameter-clauseÂ− subscript-result â ->Â−attributesÂ−optÂ−typeÂ− Grammar of an operator declaration operator-declaration â prefix-operator-declarationÂ− postfix-operator-declarationÂ− infix-operator-declarationÂ− prefix-operator-declaration â operatorÂ−prefixÂ−operatorÂ−{Â−}Â− postfix-operator-declaration â infix-operator-declaration â infix-operator-attributes â precedence-clause â precedence-level â associativity-clause â associativity â operatorÂ−postfixÂ−operatorÂ−{Â−}Â− operatorÂ−infixÂ−operatorÂ−{Â−infix-operator-attributesÂ−optÂ−}Â− precedence-clauseÂ−optÂ−associativity-clauseÂ−optÂ− precedenceÂ−precedence-levelÂ− Digit through 255 associativityÂ−associativityÂ− leftÂ− rightÂ− noneÂ− Patterns Grammar of a pattern pattern â wildcard-patternÂ−type-annotationÂ−optÂ− pattern â identifier-patternÂ−type-annotationÂ−optÂ− pattern â value-binding-patternÂ− pattern â tuple-patternÂ−type-annotationÂ−optÂ− pattern â enum-case-patternÂ− pattern â type-casting-patternÂ− pattern â expression-patternÂ− Grammar of a wildcard pattern wildcard-pattern â _Â− Grammar of an identifier pattern Patterns 338 The Swift Programming Language for iOS&OS X Apps identifier-pattern â identifierÂ− Grammar of a value-binding pattern value-binding-pattern â varÂ−patternÂ− letÂ−patternÂ− Grammar of a tuple pattern tuple-pattern â (Â−tuple-pattern-element-listÂ−optÂ−)Â− tuple-pattern-element-list â tuple-pattern-elementÂ− tuple-pattern-elementÂ−,Â−tuple-pattern-element-listÂ− tuple-pattern-element â patternÂ− Grammar of an enumeration case pattern enum-case-pattern â type-identifierÂ−optÂ−.Â−enum-case-nameÂ−tuple-patternÂ−optÂ− Grammar of a type casting pattern type-casting-pattern â is-patternÂ− as-patternÂ− is-pattern â isÂ−typeÂ− as-pattern â patternÂ−asÂ−typeÂ− Grammar of an expression pattern expression-pattern â expressionÂ− Attributes Grammar of an attribute attribute â @Â−attribute-nameÂ−attribute-argument-clauseÂ−optÂ− attribute-name â identifierÂ− attribute-argument-clause â attributes â (Â−balanced-tokensÂ−optÂ−)Â− attributeÂ−attributesÂ−optÂ− balanced-tokens â balanced-tokenÂ−balanced-tokensÂ−optÂ− balanced-token â (Â−balanced-tokensÂ−optÂ−)Â− balanced-token â [Â−balanced-tokensÂ−optÂ−]Â− balanced-token â {Â−balanced-tokensÂ−optÂ−}Â− Attributes 339 The Swift Programming Language for iOS&OS X Apps balanced-token â Any identifier, keyword, literal, or operator balanced-token â Any punctuation except (Â−, )Â−, [Â−, ]Â−, {Â−, or }Â− Expressions Grammar of an expression expression â prefix-expressionÂ−binary-expressionsÂ−optÂ− expression-list â expressionÂ− expressionÂ−,Â−expression-listÂ− Grammar of a prefix expression prefix-expression â prefix-operatorÂ−optÂ−postfix-expressionÂ− prefix-expression â in-out-expressionÂ− in-out-expression â &Â−identifierÂ− Grammar of a binary expression binary-expression â binary-operatorÂ−prefix-expressionÂ− binary-expression â assignment-operatorÂ−prefix-expressionÂ− binary-expression â conditional-operatorÂ−prefix-expressionÂ− binary-expression â type-casting-operatorÂ− binary-expressions â binary-expressionÂ−binary-expressionsÂ−optÂ− Grammar of an assignment operator assignment-operator â =Â− Grammar of a conditional operator conditional-operator â ?Â−expressionÂ−:Â− Grammar of a type-casting operator type-casting-operator â isÂ−typeÂ− asÂ−?Â−optÂ−typeÂ− Grammar of a primary expression primary-expression â identifierÂ−generic-argument-clauseÂ−optÂ− primary-expression â literal-expressionÂ− Expressions 340 The Swift Programming Language for iOS&OS X Apps primary-expression â self-expressionÂ− primary-expression â superclass-expressionÂ− primary-expression â closure-expressionÂ− primary-expression â parenthesized-expressionÂ− primary-expression â implicit-member-expressionÂ− primary-expression â wildcard-expressionÂ− Grammar of a literal expression literal-expression â literalÂ− literal-expression â array-literalÂ− dictionary-literalÂ− literal-expression â FILE Â− LINE Â− COLUMN Â− FUNCTION Â− array-literal â [Â−array-literal-itemsÂ−optÂ−]Â− array-literal-items â array-literal-itemÂ−,Â−optÂ− array-literal-itemÂ−,Â−array-literal-itemsÂ− array-literal-item â expressionÂ− dictionary-literal â [Â−dictionary-literal-itemsÂ−]Â− [Â−:Â−]Â− dictionary-literal-items â dictionary-literal-itemÂ−,Â−optÂ− dictionary-literal-itemÂ−,Â−dictionary-literal-itemsÂ− dictionary-literal-item â expressionÂ−:Â−expressionÂ− Grammar of a self expression self-expression â selfÂ− self-expression â selfÂ−.Â−identifierÂ− self-expression â selfÂ−[Â−expressionÂ−]Â− self-expression â selfÂ−.Â−initÂ− Grammar of a superclass expression superclass-expression â superclass-method-expressionÂ− superclass-subscript-expressionÂ− superclass-initializer-expressionÂ− superclass-method-expression â superclass-subscript-expression â Expressions superÂ−.Â−identifierÂ− superÂ−[Â−expressionÂ−]Â− 341 The Swift Programming Language for iOS&OS X Apps superclass-initializer-expression â superÂ−.Â−initÂ− Grammar of a closure expression closure-expression â {Â−closure-signatureÂ−optÂ−statementsÂ−}Â− closure-signature â parameter-clauseÂ−function-resultÂ−optÂ−inÂ− closure-signature â identifier-listÂ−function-resultÂ−optÂ−inÂ− closure-signature â capture-listÂ−parameter-clauseÂ−function-resultÂ−optÂ−inÂ− closure-signature â capture-listÂ−identifier-listÂ−function-resultÂ−optÂ−inÂ− closure-signature â capture-listÂ−inÂ− capture-list â [Â−capture-specifierÂ−expressionÂ−]Â− capture-specifier â weakÂ− unownedÂ− unowned(safe)Â− unowned(unsafe)Â− Grammar of a implicit member expression implicit-member-expression â Â−identifierÂ− Grammar of a parenthesized expression parenthesized-expression â expression-element-list â expression-element â (Â−expression-element-listÂ−optÂ−)Â− expression-elementÂ− expression-elementÂ−,Â−expression-element-listÂ− expressionÂ− identifierÂ−:Â−expressionÂ− Grammar of a wildcard expression wildcard-expression â _Â− Grammar of a postfix expression postfix-expression â primary-expressionÂ− postfix-expression â postfix-expressionÂ−postfix-operatorÂ− postfix-expression â function-call-expressionÂ− postfix-expression â initializer-expressionÂ− postfix-expression â explicit-member-expressionÂ− postfix-expression â postfix-self-expressionÂ− postfix-expression â dynamic-type-expressionÂ− Expressions 342 The Swift Programming Language for iOS&OS X Apps postfix-expression â subscript-expressionÂ− postfix-expression â forced-value-expressionÂ− postfix-expression â optional-chaining-expressionÂ− Grammar of a function call expression function-call-expression â postfix-expressionÂ−parenthesized-expressionÂ− function-call-expression â postfix-expressionÂ−parenthesized-expressionÂ−optÂ−trailing-closureÂ− trailing-closure â closure-expressionÂ− Grammar of an initializer expression initializer-expression â postfix-expressionÂ−.Â−initÂ− Grammar of an explicit member expression explicit-member-expression â postfix-expressionÂ−.Â−decimal-digitÂ− explicit-member-expression â postfix-expressionÂ−.Â−identifierÂ−generic-argument-clauseÂ−optÂ− Grammar of a self expression postfix-self-expression â postfix-expressionÂ−.Â−selfÂ− Grammar of a dynamic type expression dynamic-type-expression â postfix-expressionÂ−.Â−dynamicTypeÂ− Grammar of a subscript expression subscript-expression â postfix-expressionÂ−[Â−expression-listÂ−]Â− Grammar of a forced-value expression forced-value-expression â postfix-expressionÂ−!Â− Grammar of an optional-chaining expression optional-chaining-expression â postfix-expressionÂ−?Â− Lexical Structure Grammar of an identifier identifier â identifier-headÂ−identifier-charactersÂ−optÂ− Lexical Structure 343 The Swift Programming Language for iOS&OS X Apps identifier â `Â−identifier-headÂ−identifier-charactersÂ−optÂ−`Â− identifier â implicit-parameter-nameÂ− identifier-list â identifierÂ− identifierÂ−,Â−identifier-listÂ− identifier-head â Upper- or lowercase letter A through Z identifier-head â U+00A8, U+00AA, U+00AD, U+00AF, U+00B2â identifier-head â U+00BCâ U+00F8â U+00FF U+00BE, U+00C0â identifier-head â U+0100â U+180Fâ U+1DBF U+02FF, U+0370â identifier-head â U+1FFF U+1E00â U+00D6, U+00D8â U+167F, U+1681â identifier-head â U+200Bâ U+2060â U+206F U+200D, U+202Aâ identifier-head â U+2070â U+20CF, U+2100â identifier-head â U+2C00â U+2DFF or U+2E80â identifier-head â U+3004â U+3007, U+3021â identifier-head â U+F900â U+FE30â U+FE44 U+FD3D, U+FD40â identifier-head â U+FFFD U+FE47â U+00B5, or U+00B7â U+00F6, or U+180D, or U+202E, U+203Fâ U+2040, U+2054, or U+218F, U+2460â U+24FF, or U+2776â U+2793 U+303F, or U+3040â U+D7FF U+2FFF U+302F, U+3031â U+FDCF, U+FDF0â U+FE1F, or identifier-head â U+10000â U+40000â U+4FFFD U+1FFFD, U+20000â U+2FFFD, U+30000â U+3FFFD, or identifier-head â U+50000â U+80000â U+8FFFD U+5FFFD, U+60000â U+6FFFD, U+70000â U+7FFFD, or identifier-head â U+90000â U+C0000â U+CFFFD U+9FFFD, U+A0000â U+AFFFD, U+B0000â identifier-head â U+DFFFD or U+E0000â U+D0000â identifier-character â Digit through identifier-character â U+FE20â U+FE2F U+0300â identifier-character â identifier-headÂ− identifier-characters â Lexical Structure U+00BA U+036F, U+1DC0â U+BFFFD, or U+EFFFD U+1DFF, U+20D0â U+20FF, or identifier-characterÂ−identifier-charactersÂ−optÂ− 344 The Swift Programming Language for iOS&OS X Apps implicit-parameter-name â $Â−decimal-digitsÂ− Grammar of a literal literal â integer-literalÂ− floating-point-literalÂ− string-literalÂ− Grammar of an integer literal integer-literal â binary-literalÂ− integer-literal â octal-literalÂ− integer-literal â decimal-literalÂ− integer-literal â hexadecimal-literalÂ− binary-literal â 0bÂ−binary-digitÂ−binary-literal-charactersÂ−optÂ− binary-digit â Digit or binary-literal-character â binary-digitÂ− _Â− binary-literal-characters â octal-literal â octal-digit â binary-literal-characterÂ−binary-literal-charactersÂ−optÂ− 0oÂ−octal-digitÂ−octal-literal-charactersÂ−optÂ− Digit through octal-literal-character â octal-digitÂ− _Â− octal-literal-characters â decimal-literal â decimal-digit â decimal-digits â octal-literal-characterÂ−octal-literal-charactersÂ−optÂ− decimal-digitÂ−decimal-literal-charactersÂ−optÂ− Digit through decimal-digitÂ−decimal-digitsÂ−optÂ− decimal-literal-character â decimal-literal-characters â hexadecimal-literal â hexadecimal-digit â decimal-digitÂ− _Â− decimal-literal-characterÂ−decimal-literal-charactersÂ−optÂ− 0xÂ−hexadecimal-digitÂ−hexadecimal-literal-charactersÂ−optÂ− Digit through 9, a through f, or A through F hexadecimal-literal-character â hexadecimal-digitÂ− _Â− hexadecimal-literal-characters â hexadecimal-literal-characterÂ−hexadecimal-literal-charactersÂ−optÂ− Grammar of a floating-point literal Lexical Structure 345 The Swift Programming Language for iOS&OS X Apps floating-point-literal â decimal-literalÂ−decimal-fractionÂ−optÂ−decimal-exponentÂ−optÂ− floating-point-literal â hexadecimal-literalÂ−hexadecimal-fractionÂ−optÂ−hexadecimal-exponentÂ− decimal-fraction â Â−decimal-literalÂ− decimal-exponent â floating-point-eÂ−signÂ−optÂ−decimal-literalÂ− hexadecimal-fraction â Â−hexadecimal-literalÂ−optÂ− hexadecimal-exponent â floating-point-pÂ−signÂ−optÂ−hexadecimal-literalÂ− floating-point-e â eÂ− EÂ− floating-point-p â pÂ− PÂ− sign â +Â− -Â− Grammar of a string literal string-literal â quoted-text â "Â−quoted-textÂ−"Â− quoted-text-itemÂ−quoted-textÂ−optÂ− quoted-text-item â escaped-characterÂ− quoted-text-item â \(Â−expressionÂ−)Â− quoted-text-item â Any Unicode extended grapheme cluster except "Â−, \Â−, U+000A, or U+000D escaped-character â \0Â− \\Â− \tÂ− \nÂ− \rÂ− \"Â− \'Â− escaped-character â \xÂ−hexadecimal-digitÂ−hexadecimal-digitÂ− escaped-character â \uÂ−hexadecimal-digitÂ−hexadecimal-digitÂ−hexadecimal-digitÂ−hexadecimal-digitÂ− escaped-character â \UÂ−hexadecimal-digitÂ−hexadecimal-digitÂ−hexadecimal-digitÂ−hexadecimal-digitÂ−hexadecimal-digitÂ−hexade Grammar of operators operator â operator-characterÂ−operatorÂ−optÂ− operator-character â /Â− =Â− -Â− +Â− !Â− *Â− %Â− Â− &Â− |Â− ^Â− ~Â− Â− binary-operator â operatorÂ− prefix-operator â operatorÂ− postfix-operator â Lexical Structure operatorÂ− 346 The Swift Programming Language for iOS&OS X Apps Types Grammar of a type type â array-typeÂ− function-typeÂ− type-identifierÂ− tuple-typeÂ− optional-typeÂ− implicitly-unwrapped-optional-typeÂ− protocol-composition-typeÂ− metatype-typeÂ− Grammar of a type annotation type-annotation â :Â−attributesÂ−optÂ−typeÂ− Grammar of a type identifier type-identifier â type-nameÂ−generic-argument-clauseÂ−optÂ− type-nameÂ−generic-argument-clauseÂ−optÂ−.Â−type-identifierÂ− type-name â identifierÂ− Grammar of a tuple type tuple-type â (Â−tuple-type-bodyÂ−optÂ−)Â− tuple-type-body â tuple-type-element-listÂ− Â−optÂ− tuple-type-element-list â tuple-type-elementÂ− tuple-type-elementÂ−,Â−tuple-type-element-listÂ− tuple-type-element â attributesÂ−optÂ−inoutÂ−optÂ−typeÂ− inoutÂ−optÂ−element-nameÂ−type-annotationÂ− element-name â identifierÂ− Grammar of a function type function-type â typeÂ−->Â−typeÂ− Grammar of an array type array-type â typeÂ−[Â−]Â− array-typeÂ−[Â−]Â− Grammar of an optional type optional-type â typeÂ−?Â− Grammar of an implicitly unwrapped optional type implicitly-unwrapped-optional-type â typeÂ−!Â− Grammar of a protocol composition type protocol-composition-type â Types protocolÂ−Â− 347 The Swift Programming Language for iOS&OS X Apps protocol-identifier-list â protocol-identifier â protocol-identifierÂ− protocol-identifierÂ−,Â−protocol-identifier-listÂ− type-identifierÂ− Grammar of a metatype type metatype-type â typeÂ−.Â−TypeÂ− typeÂ−.Â−ProtocolÂ− Grammar of a type inheritance clause type-inheritance-clause â type-inheritance-list â Types :Â−type-inheritance-listÂ− type-identifierÂ− type-identifierÂ−,Â−type-inheritance-listÂ− 348 ... 62 For Loops 63 For- In .63 ii The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps For- Condition-Increment.. .The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for iOS&OS X Apps .1 About Swift A Swift Tour ... Cycles for Closures 183 Resolving Strong Reference Cycles for Closures .186 v The Swift Programming Language for iOS&OS X Apps Table of Contents The Swift Programming Language for

Ngày đăng: 27/08/2017, 14:51

TỪ KHÓA LIÊN QUAN

w