Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Welcome to Swift
About Swift
A Swift Tour
Simple Values
Control Flow
Functions and Closures
Objects and Classes
Enumerations and Structures
Protocols and Extensions
Generics
Language Guide
The Basics
Constants and Variables
Declaring Constants and Variables
Type Annotations
Naming Constants and Variables
Printing Constants and Variables
Comments
Semicolons
Integers
Integer Bounds
Int
UInt
Floating-Point Numbers
Type Safety and Type Inference
Numeric Literals
Numeric Type Conversion
Integer Conversion
Integer and Floating-Point Conversion
Type Aliases
Booleans
Tuples
Optionals
If Statements and Forced Unwrapping
Optional Binding
nil
Implicitly Unwrapped Optionals
Assertions
Debugging with Assertions
When to Use Assertions
Basic Operators
Terminology
Assignment Operator
Arithmetic Operators
Remainder Operator
Floating-Point Remainder Calculations
Increment and Decrement Operators
Unary Minus Operator
Unary Plus Operator
Compound Assignment Operators
Comparison Operators
Ternary Conditional Operator
Range Operators
Closed Range Operator
Half-Closed Range Operator
Logical Operators
Logical NOT Operator
Logical AND Operator
Logical OR Operator
Combining Logical Operators
Explicit Parentheses
Strings and Characters
String Literals
Initializing an Empty String
String Mutability
Strings Are Value Types
Working with Characters
Counting Characters
Concatenating Strings and Characters
String Interpolation
Comparing Strings
String Equality
Prefix and Suffix Equality
Uppercase and Lowercase Strings
Unicode
Unicode Terminology
Unicode Representations of Strings
UTF-8
UTF-16
Unicode Scalars
Collection Types
Arrays
Array Type Shorthand Syntax
Array Literals
Accessing and Modifying an Array
Iterating Over an Array
Creating and Initializing an Array
Dictionaries
Dictionary Literals
Accessing and Modifying a Dictionary
Iterating Over a Dictionary
Creating an Empty Dictionary
Mutability of Collections
Control Flow
For Loops
For-In
For-Condition-Increment
While Loops
While
Do-While
Conditional Statements
If
Switch
No Implicit Fallthrough
Range Matching
Tuples
Value Bindings
Where
Control Transfer Statements
Continue
Break
Break in a Loop Statement
Break in a Switch Statement
Fallthrough
Labeled Statements
Functions
Defining and Calling Functions
Function Parameters and Return Values
Multiple Input Parameters
Functions Without Parameters
Functions Without Return Values
Functions with Multiple Return Values
Function Parameter Names
External Parameter Names
Shorthand External Parameter Names
Default Parameter Values
External Names for Parameters with Default Values
Variadic Parameters
Constant and Variable Parameters
In-Out Parameters
Function Types
Using Function Types
Function Types as Parameter Types
Function Types as Return Types
Nested Functions
Closures
Closure Expressions
The Sort Function
Closure Expression Syntax
Inferring Type From Context
Implicit Returns from Single-Expression Closures
Shorthand Argument Names
Operator Functions
Trailing Closures
Capturing Values
Closures Are Reference Types
Enumerations
Enumeration Syntax
Matching Enumeration Values with a Switch Statement
Associated Values
Raw Values
Classes and Structures
Comparing Classes and Structures
Definition Syntax
Class and Structure Instances
Accessing Properties
Memberwise Initializers for Structure Types
Structures and Enumerations Are Value Types
Classes Are Reference Types
Identity Operators
Pointers
Choosing Between Classes and Structures
Assignment and Copy Behavior for Collection Types
Assignment and Copy Behavior for Dictionaries
Assignment and Copy Behavior for Arrays
Ensuring That an Array Is Unique
Checking Whether Two Arrays Share the Same Elements
Forcing a Copy of an Array
Properties
Stored Properties
Stored Properties of Constant Structure Instances
Lazy Stored Properties
Stored Properties and Instance Variables
Computed Properties
Shorthand Setter Declaration
Read-Only Computed Properties
Property Observers
Global and Local Variables
Type Properties
Type Property Syntax
Querying and Setting Type Properties
Methods
Instance Methods
Local and External Parameter Names for Methods
Modifying External Parameter Name Behavior for Methods
The self Property
Modifying Value Types from Within Instance Methods
Assigning to self Within a Mutating Method
Type Methods
Subscripts
Subscript Syntax
Subscript Usage
Subscript Options
Inheritance
Defining a Base Class
Subclassing
Overriding
Accessing Superclass Methods, Properties, and Subscripts
Overriding Methods
Overriding Properties
Overriding Property Getters and Setters
Overriding Property Observers
Preventing Overrides
Initialization
Setting Initial Values for Stored Properties
Initializers
Default Property Values
Customizing Initialization
Initialization Parameters
Local and External Parameter Names
Optional Property Types
Modifying Constant Properties During Initialization
Default Initializers
Memberwise Initializers for Structure Types
Initializer Delegation for Value Types
Class Inheritance and Initialization
Designated Initializers and Convenience Initializers
Initializer Chaining
Two-Phase Initialization
Initializer Inheritance and Overriding
Automatic Initializer Inheritance
Syntax for Designated and Convenience Initializers
Designated and Convenience Initializers in Action
Setting a Default Property Value with a Closure or Function
Deinitialization
How Deinitialization Works
Deinitializers in Action
Automatic Reference Counting
How ARC Works
ARC in Action
Strong Reference Cycles Between Class Instances
Resolving Strong Reference Cycles Between Class Instances
Weak References
Unowned References
Unowned References and Implicitly Unwrapped Optional Properties
Strong Reference Cycles for Closures
Resolving Strong Reference Cycles for Closures
Defining a Capture List
Weak and Unowned References
Optional Chaining
Optional Chaining as an Alternative to Forced Unwrapping
Defining Model Classes for Optional Chaining
Calling Properties Through Optional Chaining
Calling Methods Through Optional Chaining
Calling Subscripts Through Optional Chaining
Linking Multiple Levels of Chaining
Chaining on Methods With Optional Return Values
Type Casting
Defining a Class Hierarchy for Type Casting
Checking Type
Downcasting
Type Casting for Any and AnyObject
AnyObject
Any
Nested Types
Nested Types in Action
Referring to Nested Types
Extensions
Extension Syntax
Computed Properties
Initializers
Methods
Mutating Instance Methods
Subscripts
Nested Types
Protocols
Protocol Syntax
Property Requirements
Method Requirements
Mutating Method Requirements
Protocols as Types
Delegation
Adding Protocol Conformance with an Extension
Declaring Protocol Adoption with an Extension
Collections of Protocol Types
Protocol Inheritance
Protocol Composition
Checking for Protocol Conformance
Optional Protocol Requirements
Generics
The Problem That Generics Solve
Generic Functions
Type Parameters
Naming Type Parameters
Generic Types
Type Constraints
Type Constraint Syntax
Type Constraints in Action
Associated Types
Associated Types in Action
Extending an Existing Type to Specify an Associated Type
Where Clauses
Advanced Operators
Bitwise Operators
Bitwise NOT Operator
Bitwise AND Operator
Bitwise OR Operator
Bitwise XOR Operator
Bitwise Left and Right Shift Operators
Shifting Behavior for Unsigned Integers
Shifting Behavior for Signed Integers
Overflow Operators
Value Overflow
Value Underflow
Division by Zero
Precedence and Associativity
Operator Functions
Prefix and Postfix Operators
Compound Assignment Operators
Equivalence Operators
Custom Operators
Precedence and Associativity for Custom Infix Operators
Language Reference
About the Language Reference
How to Read the Grammar
Lexical Structure
Whitespace and Comments
Identifiers
Keywords
Literals
Integer Literals
Floating-Point Literals
String Literals
Operators
Types
Type Annotation
Type Identifier
Tuple Type
Function Type
Array Type
Optional Type
Implicitly Unwrapped Optional Type
Protocol Composition Type
Metatype Type
Type Inheritance Clause
Type Inference
Expressions
Prefix Expressions
Binary Expressions
Assignment Operator
Ternary Conditional Operator
Type-Casting Operators
Primary Expressions
Literal Expression
Self Expression
Superclass Expression
Closure Expression
Implicit Member Expression
Parenthesized Expression
Wildcard Expression
Postfix Expressions
Function Call Expression
Initializer Expression
Explicit Member Expression
Postfix Self Expression
Dynamic Type Expression
Subscript Expression
Forced-Value Expression
Optional-Chaining Expression
Statements
Loop Statements
For Statement
For-In Statement
While Statement
Do-While Statement
Branch Statements
If Statement
Switch Statement
Switch Statements Must Be Exhaustive
Execution Does Not Fall Through Cases Implicitly
Labeled Statement
Control Transfer Statements
Break Statement
Continue Statement
Fallthrough Statement
Return Statement
Declarations
Module Scope
Code Blocks
Import Declaration
Constant Declaration
Variable Declaration
Stored Variables and Stored Variable Properties
Computed Variables and Computed Properties
Stored Variable Observers and Property Observers
Class and Static Variable Properties
Type Alias Declaration
Function Declaration
Parameter Names
Special Kinds of Parameters
Special Kinds of Methods
Curried Functions and Methods
Enumeration Declaration
Enumerations with Cases of Any Type
Enumerations with Raw Cases Values
Accessing Enumeration Cases
Structure Declaration
Class Declaration
Protocol Declaration
Protocol Property Declaration
Protocol Method Declaration
Protocol Initializer Declaration
Protocol Subscript Declaration
Protocol Associated Type Declaration
Initializer Declaration
Deinitializer Declaration
Extension Declaration
Subscript Declaration
Operator Declaration
Attributes
Declaration Attributes
Declaration Attributes Used by Interface Builder
Type Attributes
Patterns
Wildcard Pattern
Identifier Pattern
Value-Binding Pattern
Tuple Pattern
Enumeration Case Pattern
Type-Casting Patterns
Expression Pattern
Generic Parameters and Arguments
Generic Parameter Clause
Where Clauses
Generic Argument Clause
Summary of the Grammar
Statements
Generic Parameters and Arguments
Declarations
Patterns
Attributes
Expressions
Lexical Structure
Types
Copyright and Notices
Table of Contents
← Prev
Back
Next →
← Prev
Back
Next →