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

Book description

Through this guide's carefully constructed explanations and examples, you will develop an understanding of Swift grammar and the elements of effective Swift style - all thoroughly revised for Swift 5.3 and Xcode 12.

 

Based on Big Nerd Ranchs popular Swift training and its well-tested materials and methodology, this guide teaches concepts and coding through hands-on exercises. You will explore Swift features in Xcode playgrounds, and you will end by building sample apps for the command line and for macOS and iOS.

 

After working through the book, you will have the skills to confidently dive into learning app development for Apple platforms like iOS and macOS.

Table of contents

  1. Title Page
  2. Dedication
  3. Acknowledgments
  4. Table of Contents
  5. 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
  6. I. Getting Started
    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
    2. 2. Types, Constants, and Variables
      1. Types
      2. Constants vs Variables
      3. String Interpolation
      4. Bronze Challenge
  7. II. The Basics
    1. 3. Conditionals
      1. if/else
      2. Ternary Operator
      3. Nested ifs
      4. else if
      5. Bronze Challenge
    2. 4. Numbers
      1. Integers
      2. Creating Integer Instances
      3. Operations on Integers
        1. Integer division
        2. Operator shorthand
        3. Overflow operators
      4. Converting Between Integer Types
      5. Floating-Point Numbers
      6. Ranges of Numbers
      7. Bronze Challenge
      8. For the More Curious: Numeric Literals
    3. 5. Switch
      1. Switch Syntax
        1. Ranges
        2. Value binding
        3. where clauses
      2. Tuples and Pattern Matching
      3. switch vs if/else
      4. Bronze Challenge
      5. Silver Challenge
    4. 6. Loops
      1. for-in Loops
        1. where
      2. while Loops
      3. repeat-while Loops
      4. Control Transfer Statements in Loops
      5. Silver Challenge
    5. 7. Strings
      1. Working with Strings
        1. Characters
      2. Unicode
        1. Unicode scalars
        2. Canonical equivalence
          1. Counting elements
          2. Indices and ranges
      3. Bronze Challenge
      4. Silver Challenge
      5. For the More Curious: Substrings
      6. For the More Curious: Multiline Strings
  8. III. Collections and Functions
    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
    2. 9. Optionals
      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
    3. 10. Dictionaries
      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
    4. 11. Sets
      1. What Is a Set?
      2. Getting a Set
      3. Working with Sets
        1. Unions
        2. Intersections
        3. Disjoint
      4. Moving Between Types
      5. Bronze Challenge
      6. Silver Challenge
    5. 12. Functions
      1. A Basic Function
      2. Function Parameters
        1. Parameter names
        2. Default parameter values
        3. In-out parameters
      3. Returning from a Function
      4. Nested Function Definitions and Scope
      5. Multiple Returns
      6. Optional Return Types
      7. Exiting Early from a Function
      8. Function Types
      9. Bronze Challenge
      10. Silver Challenge
      11. For the More Curious: Void
      12. For the More Curious: Variadic Parameters
    6. 13. Closures
      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(_:_:)
      7. Bronze Challenge
      8. Silver Challenge
      9. Gold Challenge
      10. For the More Curious: Functions as Return Types
  9. IV. Enumerations, Structures, and Classes
    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
    2. 15. Structs and Classes
      1. A New Project
      2. Structures
      3. Instance Methods
        1. Mutating methods
      4. Classes
        1. A Monster class
        2. Inheritance
          1. A Zombie subclass
          2. Preventing overriding
          3. The zombie problem
          4. Polymorphism and type casting
      5. Looking Ahead: What Is the Real Difference?
      6. Bronze Challenge
      7. Silver Challenge
      8. For the More Curious: Type Methods
    3. 16. Properties
      1. Basic Stored Properties
      2. Nested Types
      3. Lazy Stored Properties
      4. Computed Properties
        1. A getter and a setter
      5. Property Observers
      6. Type Properties
      7. Access Control
        1. Controlling getter and setter visibility
      8. Bronze Challenge
      9. Silver Challenge
      10. Gold Challenge
      11. For the More Curious: Key Paths
    4. 17. Initialization
      1. Initializer Syntax
      2. Struct Initialization
        1. Default initializers for structs
        2. Custom initializers for structs
          1. Initializer delegation
      3. Class Initialization
        1. Default initializers for classes
        2. Initialization and class inheritance
          1. Automatic initializer inheritance
          2. Designated initializers for classes
          3. Convenience initializers for classes
        3. Required initializers for classes
        4. Deinitialization
      4. Failable Initializers
        1. A failable Town initializer
      5. Initialization Going Forward
      6. Silver Challenge
      7. Gold Challenge
      8. For the More Curious: Initializer Parameters
    5. 18. Value vs Reference Types
      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
  10. V. Advanced Swift
    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
    2. 20. Extensions
      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
      3. Bronze Challenge
      4. Silver Challenge
    3. 21. Generics
      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
    4. 22. Protocol Extensions
      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
    5. 23. Error Handling
      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
    6. 24. Memory Management and ARC
      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?
    7. 25. Equatable, Comparable, and Hashable
      1. Equatable
        1. Infix operators
        2. Buy one method, get another free!
      2. Comparable
        1. Protocol inheritance
      3. Hashable
        1. Custom hashing
      4. Bronze Challenge
      5. Silver Challenge
      6. Gold Challenge
      7. Platinum Challenge
      8. For the More Curious: Custom Operators
    8. 26. Property Wrappers
      1. Defining a Property Wrapper
        1. Additional configuration
      2. Accessing the Wrapper Itself
      3. Projecting Related Values
      4. Bronze Challenge
      5. Silver Challenge
      6. Gold Challenge
  11. VI. Writing Applications
    1. 27. Command-Line Utilities
      1. Introduction to the Command Line
      2. Building the Word Finder
        1. Loading the words from disk
      3. Retrieving Command-Line Arguments
      4. Receiving Input Interactively
      5. Running Your App from the Command Line
      6. Parsing Command-Line Arguments with ArgumentParser
        1. Adding ArgumentParser to your project
        2. Declaring arguments for ArgumentParser to parse
      7. Silver Challenge
      8. Gold Challenge
    2. 28. iOS and macOS Apps
      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
      5. Observing Changes to the Store
      6. Saving and Loading User Data
      7. Supporting macOS
      8. Bronze Challenge
      9. Silver Challenge
      10. Gold Challenge
  12. 29. Conclusion
    1. Where to Go from Here?
    2. Shameless Plugs
    3. An Invitation to the Community
  13. Index

Product information

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