+ (addition operator), 27
&& (AND operator), 38
= (assignment operator), 19
... (closed range operator), 48
/ (division operator), 27
== (equal to operator), 36
> (greater than operator), 37
< (less than operator), 37
% (modulo operator), 30, 55, 105
* (multiplication operator), 27
?? (nil coalescing operator), 65, 151, 185
!= (not equal to operator), 36
! (NOT operator), 38
|| (OR operator), 38
| (pipe), 248
- (subtraction operator), 27
A
addition operator (+), 27
alpha (transparency setting), 286–287
anchorPoint property, 208–209, 287
AND operator (&&), 38
app icon, adding to project, 125
Apple ID (Apple account)
creating, 5
for running app on a device, 14
signing in to Xcode, 7
applications. See apps
application delegate, 174
managing app lifecycle, 177
shared property, 178
apps, 3. See also BirthdayTracker; Hello World; Schoolhouse Skateboarder
creating, 5–9, 122–125, 205–206
arc4random_uniform() function, 229
arguments, 82
in a function call, 83
custom, 90
removing, 90–91
arithmetic operators, 27–30
arrays
accessing items, 69
adding items, 70
index, 67
Index out of range error, 69–70
initializing, 68
mutable and immutable, 68
properties, 73
removing items, 71–72
replacing items, 72
artwork. See images
asset catalogs, 125, 206–207, 214
assignment operator (=), 19
auto layout, 138–139
B
behavior, of an object, 96
bitmasks, 247–249
BirthdayTracker (app), 121, 122
AddBirthdayViewController class, 144, 145
alphabetizing birthdays, 185–186
app icon, adding, 125
Birthday class, 142–144, 175–176
BirthdaysTableViewController class, 127–129, 156–158
creating project, 122–125
displaying birthdays
connecting user input to display, 166–172
creating list of birthdays, 155–166
display name, adding, 126
notifications
permissions for, 192–194
removing, 199
scheduling, 194–199
removing birthdays, 186–189
saving birthdays, 173–181
user input
Add button, 130–133
auto layout, 138–139
date picker, 137–138, 147–150, 152
Save button, 139, 150–151, 153
text fields, 136–137, 147–149, 151–152
user interface labels, 134–136
body, of a function, 83
Bool data type, 24
Boolean
expressions, 36–40
values, 24
break keyword, 105–106
Bundle Identifier, 9
bundles, 294
C
Calendar class, 195–197
calling a function, 83
cases, of enums, 259–260, 280–281
casting, 26. See also downcasting
CGPoint struct, 210
CGRect struct, 210
CGVector data type, 240
classes, 95
accessing properties, 98–100
creating, 96
definition, writing, 96–97
inheritance, 108–110
instances, 96
naming, 96–97
objects, 95
self keyword, 106–107
superclasses and subclasses, 108–110
class keyword, 96
closed range operator (...), 48
code blocks
nesting, 54–55
scope, 55–57
collections, looping through, 50
comments, 32–33
comparison operators, 36–38
compound assignment operators, 31–32
compound Boolean expressions, 38–40
conditional statements, 36, 40–45
console. See debug area
constants
declaring and creating, 20
naming, 22
when to use, 21
Core Data framework, 174
deleting managed objects, 188
entities and attributes, 174–176
fetching managed objects, 181–182
managed object context, 178
saving managed objects, 180
sortDescriptors property, 185–186
count property
array, 73
dictionary, 78
creating a new project, 6, 122–125, 205–206
D
databases, 173–174. See also Core Data framework
data types, 22
Bool, 24
casting, 26
CGVector, 240
custom class, 95
declaration of, 23
Double, 24
downcasting, 113–114
Float, 24
Int, 24
String, 24–25
type inference, 25–26
UInt32, 247
Date
class, 144
data type, 159
DateComponents class, 195–197
date formatter, 159
date picker
adding, 137–138
getting date from, 152
setting a maximum date, 149–150
debug area, 10
displaying output, 83
decimal numbers, 24
definition, writing for a class, 96–97
degrees, of rotation, 255
delegation, 166–168
delegate, creating, 170–171
protocols
adopting, 168–170
creating, 168
device orientation, 124, 211–213
devices, running apps on, 14–16
dictionaries, 75
accessing values, 76–77
adding items, 77
initializing, 75–76
looping through, 78–79
mutable and immutable, 75
optionals, 76
properties, 78
removing items, 77
replacing items, 77–78
dismissing view controller, 153–154
division operator (/), 27
do-try-catch blocks, handling errors with, 180
Double data type, 24
downcasting, 113–114
E
else if statements, 41–43. See also if statements
else statements, 41. See also if statements
enums (enumerations), 259–260, 280–281
equal to operator (==), 36
errors
fixing with Xcode, 99–100
handling with do-try-catch blocks, 180
Index out of range error, 69–70
playground, 21
exhaustive switch statements, 105
F
Float data type, 24
fonts
in SpriteKit, 270
in storyboard, 12
for-in loops
collections, 50
dictionaries, 78–79
ranges, 48–49
formatting strings, 273–274
frames, 210
func keyword, 82
functions, 81
argument labels, 84, 88, 89–91
arguments, 82
body, 83
calling, 83
naming, 82
return values, 91–93
void, 82
G
game engine. See SpriteKit
game loop update(_:) method, 231–233
GameScene class, 208
gesture recognizers, 234–235
greater than operator (>), 37
graphics. See images
H
Hello World (app)
adding a label, 10–12
creating and naming, 6–9
running in simulator, 12–13
running on a device, 14–16
stopping, 13
I
IBAction, 150
IBOutlet
connecting to storyboard, 147–149
setting up, 146–147
if-let statements, 62–64
if statements, 40–43
images
adding to project, 206–207
finding, 204
sizing for devices, 213–214
suffixes, 214
implicitly unwrapped optionals, 64
index, 67. See also arrays
IndexPath struct, 165–166
inheritance, in a class, 108–110
initializers, for classes, 98
calling with input parameters, 102–103
creating
with input parameters, 101–102
without input parameters, 100–101
default, 100
init keyword, 100–102
input parameters, of a function, 82, 84–88
installing Xcode, 4–5
instances, of a class, 96
Int data type, 24
iOS, 4
iPhone simulator. See simulator
isEmpty property
array, 73
dictionary, 78
is keyword, 110
iteration, 49
K
keys, 75. See also dictionaries
L
labels
adding to storyboard, 10–11
positioning, 134–136
in SpriteKit, 268–272, 273–274
landscape vs. portrait, device orientation, 124, 211–213
less than operator (<), 37
let keyword, 20
local notifications. See notifications
logical operators, 38–40
long-press gestures, 234
loops, 47
for-in loops. See for-in loops
nesting, 54–55
while loops, 50–53
M
managed object context, 178
MARK: keyword, for marking file sections, 170
methods, 96
calling, 104
creating, 103
helper methods, 104–106
initializers, 98
selectors, 235
mobile apps, 4
modal view controller, 132
modulo operator (%), 30, 55, 105
modulus. See modulo operator
multiplication operator (*), 27
N
naming
classes, 96–97
constants and variables, 22
functions, 82
navigation controller, 129
accessing in code, 171–172
adding a title, 130
nesting code blocks, 54–55
nil coalescing operator (??), 65, 151, 185
nil value, 60
not equal to operator (!=), 36
notifications, 191
changing settings, 194
removing, 199
requesting authorization, 192–194
scheduling, 194–199
trigger, 195–196
NOT operator (!), 38
NSKeyedUnarchiver, 294
O
Objective-C, 4
Object Library, 10
objects, 95–96
opening a project, 13
operands, 27
operators
arithmetic, 27–30
comparison, 36–38
compound assignment, 31–32
logical, 38–40
order of operations, 30–31
declaring, 60
dictionary values, 76
if-let statements, 62–64
nil coalescing operator (??), 65, 151
optional binding, 62–64
unwrapping
forced, 61–62
implicit, 64
order of operations, 30–31
OR operator (||), 38
P
pan gestures, 234
parameters, of a function, 82, 84–88
parentheses
after function names, 83
for order of operations, 30–31, 39
particle emitters, 291–297
physics bodies, 240
applying forces to, 250–251
applying to sprite, 244–245, 263
shapes, 241–242
physics categories, 247
physics engine. See SpriteKit physics engine
pinch gestures, 234
pipe (|), 248
playground
debug area, 19–21
opening, 17–18
results sidebar, 18–19
PNG (Portable Network Graphics) files, 207
portrait vs. landscape, device orientation, 124, 211–213
positioning
sprites, 210, 220–221, 226–227, 263
storyboard elements, 134–136
prepare(for:sender:) method, 171–172
projects. See also individual projects
creating, 6–9, 122–125, 205–206
opening, 13
running on device, 14–16
running in simulator, 12–13
saving, 13
properties
of arrays, 73
of classes, 96–97
accessing, 98–100
default values, 97
of dictionaries, 78
protocol, for delegation, 167, 168–170
R
radians, of rotation, 255
random numbers, 229
ranges, looping through, 48–49
raw values, of enums, 259–260
rectangles, for frames, 210
refactoring code, 182
reference types, 115–116
repeat-while loops, 52–53
return keyword, 91
return values, 91–93
rotating device, in simulator, 213
running an app
in simulator, 12–13
on a device, 14–16
S
saving
birthdays, in BirthdayTracker, 173–181
managed objects, in database, 180
projects, 13
scene
in a storyboard, 10
Schoolhouse Skateboarder (app), 203
anchorPoint, setting for scene, 208–209
bricks
adding, 224–225
animating, 226–230
leaving gaps, 229–230
physics bodies for, 245–246
contacts and collisions, 246–250
creating the project, 205–206
ending the game, 254–255
game loop, 231–233
game state, 280–281
gems
collecting, 267–268
removing, 264–265
spawning, 262–264
updating, 265–267
gravity, simulating, 235–238, 240
images
displaying background, 207–211
filling the screen, 215
menus (MenuLayer class), 282
displaying, 286–288
message label, 283–285
removing, 288–289
score label, 285–286
orientation, setting, 211–213
platforms, adding multilevel, 258–262
scores
displaying with labels, 268–272
for collecting gems, 275–276
high scores, 276
updating, 272–275
skater
checking rotation of, 255
physics body for, 244–245
resetting, 220–221
Skater class
creating, 218
instantiating, 219
sounds
adding to project, 289–290
playing, 290
sparks, 291–297
speeding up the game, 257–258
starting the game, 251–254
SDK (Software Development Kit), 4
selectors, 235
self keyword, 106–107
simulator (iPhone simulator)
rotating device, 213
running app on, 12–13
SKEmitterNode, 294–295
SKLabelNode class, 269–273
SKPhysicsWorld class, 240
.sks (SpriteKit scene) files, 206, 291, 294
SKSpriteNode class
Software Development Kit (SDK), 4
sound effects
adding to project, 289–290
finding, 204
playing, in SpriteKit, 290
sparks, adding with particle emitters, 291–297
spawning, in games, 225
SpriteKit, 204
animating via actions, 284–285, 295
debug information, 223
game loop update(_:) method, 231–233
didMove(to:) method, 208, 210, 234, 253
filling the screen, 215
nodes, 223
getting by name, 273
physics engine. See SpriteKit physics engine
scene size, 215
SKEmitterNode, 294–295
SKLabelNode, 269–273
.sks (SpriteKit scene) files, 206
SKScene class, 208
SKSpriteNode class, 210
sound effects, 289–290
spawning, 225
sprites. See sprites
SpriteKit physics engine, 239
applying forces, 250–251
categoryBitMask property, 248
collisionBitMask property, 248
contacts and collisions, 246–250, 267
contactTestBitMask property, 248–249
didBegin(_:) method, 249–250, 267
gravity, 240
physics bodies, 240
applying to sprite, 244–245, 263
shapes, 241–242
physics categories, 247
SKPhysicsBody class, 241–251
SKPhysicsContactDelegate protocol, 249–250
SKPhysicsWorld class, 240
speed, 240
sprites, 204
adding, 210–211, 220, 222, 225, 263
animating, 226–229, 231–233, 284–285
children and parents, 211, 220
color, 286–287
moving, 284–285
overlapping, 221
positioning, 210, 220–221, 226–227, 263
removing, 226–227, 252, 264–265, 288
zPosition property, 220–221, 225, 270, 283
state, of an object, 95–96
adding a navigation controller, 129
adding view controllers, 127
auto layout, 138–139
elements
adding, 10
segues, 132
String data type, 24
strings, 24
concatenation, 25
embedded variables, 49
formatting, 273–274
structs, 117–118
CGPoint, 210
IndexPath, 165–166
use in Schoolhouse Skateboarder, 247
subtraction operator (-), 27
superclasses, 108–110
super keyword, 109
Swift, 4
creating file, 142–143
playground. See playground
safe language, 59
swipe gestures, 234
switch keyword, 44
T
table view, 155
cells
adding, 158–159
displaying, 164–166
data source, 162
IndexPath struct, 165
reloadData() method, 169
rows, 162–163
deleting, 187–188
editing, 187
sections, 162–163
table view controller, adding to storyboard, 127
tap gestures, 234–235
targets, for selectors, 235
text alignment
in SpriteKit, 269, 271, 283, 286
in storyboard, 12
text fields
adding, 136
reading text from, 151–152
textures, for physics bodies, 241–242, 244–245
TimeInterval data type, 231–233, 272
transparency setting (alpha), 286–287
typecasting, 110–113
type inference, 25
U
UIDatePicker class, 146, 149. See also date picker
UInt32 data type, 247
UITableViewController class, 156–157. See also table view controller
UIViewController class, 145–146. See also view controller
unsigned integers, 247
unwrapping optionals, 61–64
user interface elements, 10
User Notifications framework. See notifications.
V
value types, 115–116
variables, 18
changing value of, 20
declaring and creating, 19
naming, 22
var keyword, 19
vectors, 240
vertical pipe (|), 248
dismissing, 153–154
file, 124
in SpriteKit, 215
storyboard, 11
UIViewController class, 145
viewDidLoad() method, 145
viewWillAppear(_:) method, 146, 181
void functions, 82
W
X
.xcassets files, 207
Xcode
autocomplete, 85
creating a new project, 6, 122–125, 205–206
installing, 4–5
opening, 5
playground, 17
signing in, 7
Y
Z