CONTENTS IN DETAIL

ACKNOWLEDGMENTS

INTRODUCTION

Who Should Read This Book?

What’s in This Book?

The Companion Website

Have Fun!

PART 1: XCODE AND SWIFT

1
HELLO, WORLD!

Installing Xcode, Your Code Editor

Your First App!

Introducing the Storyboard

Adding User Interface Elements with the Object Library

Saving Your Work

Running the App on a Real Device

What You Learned

2
LEARNING TO CODE IN A PLAYGROUND

Constants and Variables

When to Use Constants vs. Variables

Naming Constants and Variables

Data Types

Declaring Data Types

Common Data Types

Type Inference

Transforming Data Types with Casting

Operators

Order of Operations

Ordering Operations with Parentheses

Compound Assignment Operators

What You Learned

3
MAKING CHOICES

Boolean Expressions

Is Equal and Is Not Equal

Greater Than and Less Than

Compound Boolean Expressions

Conditional Statements

if Statements

switch Statements

What You Learned

4
WRITING CODE THAT LOOPS

Open the Debug Area

Looping Through Ranges and Collections with for-in

Say Hello!

Say Good Morning!

Testing Conditions with while Loops

Guess My Number

Shrink Away

Which Loop to Use?

Nesting and Scope

Nesting Blocks of Code

Constant and Variable Scope

What You Learned

5
KEEPING YOUR PROGRAMS SAFE WITH OPTIONALS

What Is an Optional?

Creating Optionals

Unwrapping Optionals

A Special Kind of Operator: ??

What You Learned

6
STORING COLLECTIONS IN DICTIONARIES AND ARRAYS

Keeping Things in Order with Arrays

Using Mutable and Immutable Arrays

Using Type Inference

Accessing Items in an Array

Watching the Range

Adding Items to an Array

Combining Arrays

Removing Items from an Array

Replacing Items in an Array

Using Array Properties

Looping Over an Array

Dictionaries Are Key!

Initializing a Dictionary

Accessing Values in a Dictionary

Adding Items to a Dictionary

Removing Items from a Dictionary

Replacing Items in a Dictionary

Using Dictionary Properties

Looping Over a Dictionary

What You Learned

7
FUNCTIONS ARE A PARTY, AND YOU’RE INVITED

In with the Input, Out with the Output

Writing a Custom Function

Functions Do Even More with Input Parameters

Making Party Invitations

Inviting All Your Friends at Once

Messaging Your Guests

Argument Labels

Adding a Custom Argument Label

Removing an Argument Label

Return Values

Which Is the Bigger Box?

Conditional Returns

What You Learned

8
CUSTOM CLASSES AND STRUCTS

Making a Class

Writing a Class Definition

Storing Information in Properties

Creating an Instance of a Class

Accessing the Properties of a Class

Customizing Each Cake with Initializers

Adding a Birthday Greeting Method

Writing a Helper Method

A Special Property Called self

Class Inheritance

Creating a Superclass

Creating a Subclass

Detecting the Data Type by Typecasting

Refining the Data Type by Downcasting

Value Types and Reference Types

Using Structs

What You Learned

PART 2: BIRTHDAY TRACKER

9
CREATING BUTTONS AND SCREENS ON THE STORYBOARD

An Outline of Your App

Creating a New Xcode Project

Adding the App Icon

Displaying Your Friends’ Birthdays

Adding the Table View Controller

Adding the Navigation Controller

Adding a Button

Setting Up Control Inputs and Labels

Adding Your Friends’ Names and Birthdays

Making Your App Look Perfect on Every Device with Auto Layout

Adding Save and Cancel Buttons

What You Learned

10
ADDING A BIRTHDAY CLASS AND HANDLING USER INPUT

The Birthday Class

Creating a New File

Writing the Birthday Class

Programming User Input

Creating the Add Birthday View Controller

Connecting Code to the Input Controls

Connecting Your Code to the Storyboard

Setting a Maximum Birthdate

Saving a Birthday

Hooking Up the Save Button

Reading Text from a Text Field

Getting a Date from a Date Picker

Creating a Birthday

Adding the Cancel Button

What You Learned

11
DISPLAYING BIRTHDAYS

Making the Birthday List

Creating the Birthdays Table View Controller

Adding Cells to the Table View

Setting Up the Birthdays Table View Controller

Displaying Birthdays in a Table View

Putting It All Together

Delegation

Connecting the Two Controllers by Setting a Delegate

What You Learned

12
SAVING BIRTHDAYS

Storing Birthdays in a Database

The Birthday Entity

The Birthday Attributes

The Application Delegate

Code Cleanup

Adding More Features to Our App

Alphabetizing Birthdays

Removing Birthdays

What You Learned

13
GETTING BIRTHDAY NOTIFICATIONS

The User Notifications Framework

Registering for Local Notifications

Scheduling a Notification

Removing a Notification

What You Learned

PART 3: SCHOOLHOUSE SKATEBOARDER

14
SETTING THE STAGE

Where Do I Get Art and Sound Effects?

Making Games with Xcode’s SpriteKit

Creating the Game Project

Adding Images

The Scenery: Displaying a Background Image

How It Will Be Played: Screen Orientation

Sizing Images for Different Screen Resolutions

What You Learned

15
MAKING SCHOOLHOUSE SKATEBOARDER A REAL GAME

Our Hero, the Skateboarder

Creating a Skater Sprite Class

Importing SpriteKit

Adding Custom Properties to the Skater Class

Creating an Instance of the Skater in the Scene

Setting Up the Skater

Seeing the Skater on the Screen

Understanding SpriteKit’s Debugging Information

Hittin’ the Bricks

Creating Sidewalk Bricks

Updating Sidewalk Bricks

Filling the Screen with Bricks

Leaving Gaps to Jump

The Game Loop

Tracking the Update Time

Calculating Elapsed Time for Each Update

Adjusting Scroll Speed Using the Elapsed Time

Updating the Bricks

Up, Up, and Away—Making the Skater Jump

Using a Tap Gesture Recognizer

Simulating Gravity in a Simple Way

Checking for Landings

What You Learned

16
USING THE SPRITEKIT PHYSICS ENGINE

Setting Up the Physics World

Physics Bodies

Giving Shape to the Physics Bodies

Setting Properties of Physics Bodies

Giving the skater Sprite a Physics Body

Adding Physics Bodies to Bricks

Contacts and Collisions

Handling Contacts and Collisions

Responding to Contacts

Applying Forces to Physics Bodies

Starting and Ending the Game

Starting the Game

Ending the Game

What You Learned

17
ADJUSTING DIFFICULTY, COLLECTING GEMS, AND KEEPING SCORE

Speeding Things Up

Adding Multilevel Platforms

Defining Multiple Brick Levels

Changing How Bricks Spawn

Adding Gems to Collect

Spawning and Tracking the Gems

Deciding When to Spawn a Gem

Removing Gems

Updating Gems

Collecting Gems

Adding Scoring and Labels

Creating Labels

Tracking the Score

Updating Labels

Updating the Player’s Score

Making the Gems Valuable

Tracking the High Score

Tweaking the Gameplay

What You Learned

18
GAME STATE, MENUS, SOUNDS, AND SPECIAL EFFECTS

Tracking Game State

Adding a Menu System

Creating the MenuLayer Class

Displaying the Menu Layers When Needed

Removing the Menu Layer

Making Sounds

Adding the Sound Files

Playing the Sounds at the Right Time

Shooting Sparks

What You Learned

RESOURCES

Troubleshooting Errors

Apple Documentation

Xcode Keyboard Shortcuts

iOS Simulator Keyboard Shortcuts

Xcode Versions

INDEX

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset