O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Swift Pocket Reference, 3rd Edition

Book Description

Get quick answers for developing and debugging applications with Swift 3, the latest version of Apple’s multi-paradigm programming language. This thoroughly updated 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. Designed to work with Cocoa and Cocoa Touch, Swift can be used in tandem with Objective-C, and either language can call APIs implemented in the other.

Table of Contents

  1. Introduction
  2. Conventions Used in This Book
  3. Using Code Examples
  4. O’Reilly Safari
  5. How to Contact Us
  6. Acknowledgments
  7. Getting Started with Swift 3
    1. Swift on macOS
    2. Swift on Linux
    3. The Swift REPL
    4. Swift as a Scripting Language
    5. Swift Playgrounds on macOS
  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. Determining 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. Comparing Tuples
    6. 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. Nil-Coalescing Operator
    12. Operator Precedence
  14. Strings and Characters
    1. String Properties
    2. Comparing Strings
    3. Escape Characters in Strings
    4. String Interpolation
    5. Converting Strings to Numeric Types
    6. Converting Other Types to Strings
    7. Character-Level Access in Strings
    8. String Methods and 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 and Argument Names
    2. inout Parameters
    3. Returning Optional Values
    4. Returning Multiple Values with Tuples
    5. Default Parameter Values
    6. Variadic Parameters
    7. Function Types
  19. Closures
    1. Capturing Values
    2. Capturing Values by Reference
    3. Closure Attributes
  20. Optionals
    1. Unwrapping Optionals
    2. Implicitly Unwrapped Optionals
    3. Optional Binding
    4. Optional Chaining
  21. Program Flow
    1. Loops
    2. Conditional Execution
    3. Statement Labels
    4. Do Scopes
    5. Deferred Execution
    6. 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 and Properties in 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. Checking Types
    2. Downcasting Types
    3. The Any Types
  28. Protocols
    1. Property Requirements
    2. Method Requirements
    3. Optional Method and Property Requirements
    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 Iterator Protocol
    12. The Sequence Protocol
    13. The Collection Protocol
    14. The FloatingPoint Protocol
  29. Memory Management
    1. How Reference Counting Works
    2. Reference Cycles and Strong References
    3. Weak References
    4. Unowned References
    5. Reference Cycles and Closures
    6. Manual Memory Use
  30. Generics
    1. Generic Functions
    2. Generic Types
    3. Constraining Types
    4. Generic Protocols
  31. Custom Operators
    1. Custom Infix Operators
    2. Custom Unary Operators
    3. Custom Infix Operator Precedence Groups
  32. Ranges and Strides
    1. Ranges
    2. Strides
  33. Foundation
  34. Command-Line Arguments
  35. Conditional Compilation
  36. Declaration Attributes
    1. The @available Attribute
  37. Global (Free) Functions
  38. Changes from Swift 2