Swift Programming: The Big Nerd Ranch Guide

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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 Ranch’s 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.

Author(s): Mikey Ward
Edition: 3
Publisher: Big Nerd Ranch
Year: 2020

Language: English
Commentary: Vector PDF
Pages: 496
City: Atlanta, GA
Tags: macOS; Programming; iOS; Swift; Application Development; Object-Oriented Programming; Error Handling

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