Swift Programming: The Big Nerd Ranch Guide, 3rd Edition

Swift Programming: The Big Nerd Ranch Guide, 3rd Edition

Read it now on the O’Reilly learning platform with a 10-day free trial.

O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.

Book description

Through the authors' carefully constructed explanations and examples, you will develop an understanding of Swift grammar and the elements of effective Swift style.

Throughout the book, the authors share their insights into Swift to ensure that you understand the hows and whys of Swift and can put that understanding to use in different contexts.

After working through the book, you will have the knowledge and confidence to develop your own solutions to a wide range of programming challenges using Swift.

Show and hide more Table of contents Product information

Table of contents

  1. Introduction
    1. Learning Swift
    2. Why Swift?
    3. What About Objective-⁠C?
    4. Prerequisites
    5. How This Book Is Organized
    6. How to Use This Book
    7. Challenges and For the More Curious
    8. Typographical Conventions
    9. Necessary Hardware and Software
    10. Using an eBook
    11. Before You Begin
    1. 1. Getting Started
      1. Getting Started with Xcode
      2. Playing in a Playground
      3. Running Your Code
      4. Troubleshooting Playgrounds
      5. Varying Variables and Printing to the Console
      6. Adding Comments
      7. You Are on Your Way!
      8. Bronze Challenge
      1. Types
      2. Constants vs Variables
      3. String Interpolation
      4. Bronze Challenge
      1. 3. Conditionals
        1. if/else
        2. Ternary Operator
        3. Nested ifs
        4. else if
        5. Bronze Challenge
        1. Integers
        2. Creating Integer Instances
        3. Operations on Integers
          1. Integer division
          2. Operator shorthand
          3. Overflow operators
          1. Switch Syntax
            1. Ranges
            2. Value binding
            3. where clauses
            1. for-in Loops
              1. where
              1. Working with Strings
                1. Characters
                1. Unicode scalars
                2. Canonical equivalence
                  1. Counting elements
                  2. Indices and ranges
                  1. 8. Arrays
                    1. Creating an Array
                    2. Accessing and Modifying Arrays
                    3. Combining Arrays
                    4. Array Equality
                    5. Immutable Arrays
                    6. Documentation
                    7. Bronze Challenge
                    8. Silver Challenge
                    1. Optional Types
                    2. Optional Binding
                    3. Implicitly Unwrapped Optionals
                    4. Optional Chaining
                    5. Modifying an Optional in Place
                    6. The Nil Coalescing Operator
                    7. Bronze Challenge
                    8. Silver Challenge
                    9. Gold Challenge
                    1. Creating a Dictionary
                    2. Accessing and Modifying Values
                    3. Adding and Removing Values
                    4. Looping over a Dictionary
                    5. Immutable Dictionaries
                    6. Translating a Dictionary to an Array
                    7. Silver Challenge
                    8. Gold Challenge
                    1. What Is a Set?
                    2. Getting a Set
                    3. Working with Sets
                      1. Unions
                      2. Intersections
                      3. Disjoint
                      1. A Basic Function
                      2. Function Parameters
                        1. Parameter names
                        2. Default parameter values
                        3. In-out parameters
                        1. Closure Syntax
                        2. Closure Expression Syntax
                        3. Functions as Arguments
                        4. Closures Capture Their Enclosing Scope
                        5. Functional Programming
                        6. Higher-Order Functions
                          1. map(_:)
                          2. filter(_:)
                          3. reduce(_:_:)
                          1. 14. Enumerations
                            1. Basic Enumerations
                            2. Enumerations with Raw Values
                            3. Methods
                            4. Associated Values
                            5. Bronze Challenge
                            6. Silver Challenge
                            7. For the More Curious: Recursive Enumerations
                            1. A New Project
                            2. Structures
                            3. Instance Methods
                              1. Mutating methods
                              1. A Monster class
                              2. Inheritance
                                1. A Zombie subclass
                                2. Preventing overriding
                                3. The zombie problem
                                4. Polymorphism and type casting
                                1. Basic Stored Properties
                                2. Nested Types
                                3. Lazy Stored Properties
                                4. Computed Properties
                                  1. A getter and a setter
                                  1. Controlling getter and setter visibility
                                  1. Initializer Syntax
                                  2. Struct Initialization
                                    1. Default initializers for structs
                                    2. Custom initializers for structs
                                      1. Initializer delegation
                                      1. Default initializers for classes
                                      2. Initialization and class inheritance
                                        1. Automatic initializer inheritance
                                        2. Designated initializers for classes
                                        3. Convenience initializers for classes
                                        1. A failable Town initializer
                                        1. Value Semantics
                                        2. Reference Semantics
                                        3. Constant Value and Reference Types
                                        4. Using Value and Reference Types Together
                                        5. Copying
                                        6. Equality vs Identity
                                        7. What Should I Use?
                                        8. For the More Curious: Copy on Write
                                        1. 19. Protocols
                                          1. Formatting a Table of Data
                                          2. Protocols
                                          3. Protocol Conformance
                                          4. Protocol Inheritance
                                          5. Protocols as Types
                                          6. Protocol Composition
                                          7. Mutating Methods
                                          8. Bronze Challenge
                                          9. Silver Challenge
                                          10. Electrum Challenge
                                          11. Gold Challenge
                                          1. Extending an Existing Type
                                          2. Extending Your Own Type
                                            1. Using extensions to add protocol conformance
                                            2. Adding an initializer with an extension
                                            3. Nested types and extensions
                                            4. Extensions with methods
                                            1. Generic Data Structures
                                            2. Generic Functions and Methods
                                            3. Type Constraints
                                            4. Associated Types
                                            5. Type Constraints in where Clauses
                                            6. Generic Composition and Opaque Types
                                            7. Bronze Challenge
                                            8. Silver Challenge
                                            9. Gold Challenge
                                            10. For the More Curious: Understanding Optionals
                                            1. Modeling Exercise
                                            2. Extending Exercise
                                            3. Self Types and Type Values
                                            4. Protocol Extension where Clauses
                                            5. Default Implementations with Protocol Extensions
                                            6. Implementation Conflicts
                                            7. Bronze Challenge
                                            8. Silver Challenge
                                            9. Gold Challenge
                                            10. For the More Curious: Polymorphism and Protocol-Oriented Programming
                                            1. Classes of Errors
                                            2. Lexing an Input String
                                            3. Catching Errors
                                            4. Parsing the Token Array
                                            5. Handling Errors by Sticking Your Head in the Sand
                                            6. Swift Error-Handling Philosophy
                                            7. Bronze Challenge
                                            8. Silver Challenge
                                            9. Gold Challenge
                                            10. For the More Curious: Storing Failable Results for Later
                                            1. Memory Allocation
                                            2. Strong Reference Cycles
                                            3. Breaking Strong Reference Cycles with weak
                                            4. Reference Cycles with Closures
                                            5. Escaping and Non-Escaping Closures
                                            6. Tin Challenge
                                            7. Bronze Challenge
                                            8. Gold Challenge
                                            9. For the More Curious: A Bit of History
                                            10. For the More Curious: Do I Have the Only Reference?
                                            1. Equatable
                                              1. Infix operators
                                              2. Buy one method, get another free!
                                              1. Protocol inheritance
                                              1. Custom hashing
                                              1. Defining a Property Wrapper
                                                1. Additional configuration
                                                1. 27. Command-Line Utilities
                                                  1. Introduction to the Command Line
                                                  2. Building the Word Finder
                                                    1. Loading the words from disk
                                                    1. Adding ArgumentParser to your project
                                                    2. Declaring arguments for ArgumentParser to parse
                                                    1. Getting Started with TahDoodle
                                                    2. That is some View
                                                    3. Displaying Dynamic Data
                                                    4. Accepting User Input
                                                      1. Sharing references to value-type data
                                                      2. Interlude: Troubleshooting with property observers
                                                      1. Where to Go from Here?
                                                      2. Shameless Plugs
                                                      3. An Invitation to the Community
                                                      Show and hide more

                                                      Product information

                                                      • Title: Swift Programming: The Big Nerd Ranch Guide, 3rd Edition
                                                      • Author(s): Matthew Mathias, John Gallagher
                                                      • Release date: October 2020
                                                      • Publisher(s): Big Nerd Ranch Guides
                                                      • ISBN: 9780135266601