You are previewing Swift Pocket Reference, 2nd Edition.
O'Reilly logo
Swift Pocket Reference, 2nd Edition

Book Description

Get quick answers for developing and debugging applications with Swift, Apple’s multi-paradigm programming language. Updated to cover the latest features in Swift 2.0, this pocket reference is the perfect on-the-job tool for learning Swift’s modern language features, including type safety, generics, type inference, closures, tuples, automatic memory management, and support for Unicode.

Table of Contents

  1. Introduction
  2. Conventions Used in This Book
  3. Using Code Examples
  4. Safari® Books Online
  5. How to Contact Us
  6. Acknowledgments
  7. Getting Started with Swift 2
    1. The Swift REPL
    2. Swift as a Scripting Language
    3. Swift Playgrounds
  8. A Taste of Swift
  9. Basic Language Features
    1. Comments
    2. Semicolons
    3. Whitespace
    4. Naming Conventions
    5. Importing Code from Other Modules
  10. Types
    1. Specific Integer Types
    2. Numeric Literals
    3. Character and String Literals
    4. Type Aliases
    5. Nested Types
    6. Other Types
  11. Variables and Constants
    1. Computed Variables
    2. Variable Observers
  12. Tuples
    1. Tuple Variables and Constants
    2. Extracting Tuple Components
    3. Naming Tuple Components
    4. Using Type Aliases with Tuples
    5. Tuples as Return Types
  13. Operators
    1. No Implicit Type Conversion
    2. Arithmetic Operators
    3. Bitwise Operators
    4. Assignment Operators
    5. Comparison Operators
    6. Logical Operators
    7. Overflow Operators
    8. Type Casting Operators
    9. Range Operators
    10. Ternary Conditional Operator
    11. Operator Precedence
  14. Strings and Characters
    1. String Properties
    2. Comparing Strings
    3. Escaped Characters in Strings
    4. String Interpolation
    5. Converting Strings to Numeric Types
    6. Character-Level Access in Strings
    7. String Inherited Functionality
  15. Arrays
    1. Accessing Array Elements
    2. Array Properties
    3. Modifying a Mutable Array
    4. Iterating Over Arrays
    5. Array Inherited Functionality
    6. Slices
  16. Dictionaries
    1. Accessing Dictionary Elements
    2. Dictionary Properties
    3. Modifying a Mutable Dictionary
    4. Iterating Over Dictionaries
    5. Dictionary Inherited Functionality
  17. Sets
    1. Accessing Set Items and Properties
    2. Modifying a Mutable Set
    3. Iterating Over Sets 
    4. Set Operations
    5. Set Inherited Functionality
    6. Option Sets
  18. Functions
    1. Parameter Types
    2. Returning Optional Values
    3. Returning Multiple Values by using Tuples
    4. Local and External Parameter Names
    5. Default Parameter Values
    6. Variadic Parameters
    7. Function Types
  19. Closures
    1. Automatic Argument Names
    2. Trailing Closures
    3. Capturing Values
    4. Capturing Values by Reference
  20. Optionals
    1. Unwrapping Optionals
    2. Implicitly Unwrapped Optionals
    3. Optional Binding
    4. Optional Chaining
  21. Program Flow
    1. Loops
    2. Conditional Execution
    3. Error Handling
  22. Classes
    1. Defining a Base Class
    2. Instances
    3. Properties
    4. Methods
    5. Subscripts
    6. Member Protection
    7. Inheritance: Deriving One Class from Another
    8. Overriding Superclass Entities
    9. Preventing Overrides and Subclassing
    10. Initialization
    11. Initialization and Inheritance
    12. Deinitialization
  23. Structures
    1. Properties in Structures
    2. Methods in Structures
    3. Type Methods for Structures
    4. Initializers in Structures
  24. Enumerations
    1. Raw Member Values
    2. Associated Values
    3. Methods in Enumerations
    4. Type Methods for Enumerations
    5. Recursive Enumerations
    6. Failable Initializers in Enumerations
  25. Access Control
    1. Specifying Access Control Levels
    2. Default Access Control Levels
  26. Extensions
    1. Computed Property Extensions
    2. Initializer Extensions
    3. Method Extensions
    4. Subscript Extensions
  27. Checking and Casting Types
    1. Any and AnyObject
    2. Checking Types
    3. Downcasting Types
  28. Protocols
    1. Required Properties
    2. Required Methods
    3. Optional Methods and Properties
    4. Initializers in Protocols
    5. Adopting Protocols with Extensions
    6. Inheritance and Protocols
    7. Using a Protocol as a Type
    8. Checking Protocol Conformance
    9. Protocol Extensions
    10. Built-In Protocols
    11. The GeneratorType Protocol
    12. The SequenceType Protocol
    13. The CollectionType Protocol
  29. Memory Management
    1. How Reference Counting Works
    2. Retain Cycles and Strong References
    3. Weak References
    4. Unowned References
    5. Retain Cycles and Closures
  30. Generics
    1. Generic Functions
    2. Generic Types
    3. Constraining Types
    4. Generic Protocols
  31. Operator Overloading
    1. Overloading Unary Operators
    2. Custom Operators
    3. Custom Operator Precedence
  32. Ranges, Intervals, and Strides
    1. Ranges
    2. Intervals
    3. Strides
  33. Global Functions
  34. Changes From Swift 1.0
  35. Index