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