Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
About This eBook
Title Page
Copyright Page
Dedication Page
Contents at a Glance
Table of Contents
About the Author
Acknowledgments
We Want to Hear from You!
Reader Services
Introduction
Who Should Read This Book
Why You Should Read This Book
What You Will Learn from This Book
What Is Swift?
How This Book Is Organized
Enjoy the Ride
1. Getting Your Feet Wet
Building Blocks of Swift
Using Comments
Inference Everywhere!
Optionals: A Gift to Unwrap
Printing Your Results
Implicitly Unwrapped Optionals
Tuples
Number Types and Converting Between Them
Coming to Swift from Objective-C and C
Control Flow: Making Choices
Switching It Up: switch Statements
Stop...Hammer Time
Summary
2. Collecting Data
Using Arrays
Your First Array
A Quicker Array
Using AnyObject
What’s an Array Made Of?
Differences Between NSArrays and Swift Arrays
Modifying Arrays
Accessing Array Elements
Adding Elements to an Array
Removing Elements from Arrays
Iterating Over Arrays
Extra Bits of Arrays
Emptying an Array
Using Dictionaries
Adding, Removing, and Inserting with Dictionaries
Iterating Over Dictionaries
Extra Bits of Dictionaries
Emptying a Dictionary
Testing Dictionaries for the Presence of Values
Putting It All Together
Summary
3. Making Things Happen: Functions
Defining Functions
Return Types
Multiple Return Values
More on Parameters
External Parameter Names
Default Parameter Values
Variadic Parameters
In-Out Parameters
Functions as Types
Putting It All Together
Summary
4. Structuring Code: Enums, Structs, and Classes
Enums
Which Member Was Set?
Associated Values
Raw Values
Structs
Defining Methods in Structs
Structs Are Always Copied
Mutating Methods
Classes
Initialization
What Is a Reference Type?
Do I Use a Struct or a Class?
Forgot Your Pointer Syntax?
Property Observers
Methods in Classes
Summary
5. Making a Game
Building a User Interface (UI)
Importing Assets
Adding Buttons and Labels
The Action-Packed View Controller
Displaying the Player’s Moves
Developing the Concept for an AI
Managing the Game State
Implementing the AI Logic
Finding Victory Conditions
Moving In for the Win
Defending the AI’s Turf and Stealing Center Stage
Taking Sides
When It’s a Draw
Summary
6. Reusable Code: Closures
What Are Closures?
Closures in Other Languages
How Closures Work and Why They’re Awesome
The Closure Syntax
Inferring Using Context
Arguments Have a Shorthand, Too
Sorting a Custom Car Class
Closures Are Reference Types
Automatic Reference Counting
Strong Reference Cycles
Trailing Closures
Summary
7. Subscripts and Advanced Operators
Writing Your First Subscript
Bits and Bytes with Advanced Operators
Bitwise NOT
Bitwise AND
Bitwise OR
Bitwise XOR
Shifting Bits
UInt8, UInt16, UInt32, Int8, Int16, Int32, and So On
Value Overflow and Underflow
Customizing Operators
Making Your Own Operators
Bits and Bytes in Real Life
Summary
8. Protocols
Writing Your First Protocol
Properties
Animizable and Humanizable
Methods
Delegation
Protocols as Types
Protocols in Collections
Protocol Inheritance
Protocol Composition
Protocol Conformity
Optional Protocol Prerequisites
Optional Chaining
Back to Optional Protocol Requisites
Useful Built-in Swift Protocols
Summary
9. Becoming Flexible with Generics
The Problem That Generics Solve
Other Uses for Generics
Generics for Protocols
The where Clause
Summary
10. Games with SpriteKit
Setting Up the Project
Loading a Scene View
Importing Image Assets
The Start Screen
Custom Colors
Handling Taps
Dangerous Ground
Positioning Obstacles
Moving Obstacles
A Hero to the Rescue
Rotating Nodes
Bar Hopping
Enemies in Motion
Elements of Chance
Tracking a Brick
Tracking All Blocks
Spawned Obstacles
Generating Barriers
Hardcore Mode
Smashing Physics
Invisible Cages
A Hero’s Death
Summary
11. Games with SceneKit
Creating DAE Files
Creating a New SceneKit Project
Your SceneKit Files
Setting the Stage
Importing the Assets
Material Properties
Making the Game
Adding a Floor
Adding the Level
Placing Each Block
Creating a Hero
Bridging the Gap to Objective-C
Back to the Hero
Adding the Controls
Summary
12. Apps with UIKit
Application Types
Single-View Applications
Adding Constraints
Adding a New View
Loading a Table View
Loading Data from a URL
Summary
Index
Code Snippets
← Prev
Back
Next →
← Prev
Back
Next →