Index

Symbols

@ (at symbol), 74

^ (carat), 264

: (colon), 145

- (hyphen), 142

+ (plus sign), 35, 142

[] (square brackets), 94

A

abstract classes, 106

abstraction, 24-25

accessing

objects in collections, 218

properties

with dot syntax, 134-135

with message syntax, 133

accessors

creating with @synthesize, 138

explained, 28, 136, 226

actions

building apps with, 150-159

iOS apps, 155-157

OS X apps, 151-154

disconnecting, 161

headers, 159

IBAction, 159

OS X versus iOS, 159-161

overview, 107, 149-150

removing, 161

setting breakpoints on, 160

addObserver method, 186

addObserverForName method, 186

allObjects method, 215

alloc method, 35, 37-38, 113

allocating objects, 37-38

anonymous categories. See extensions

anyObject method, 218

AppDelegate class

.h files, 70-71

.m files, 71-73

AppIcon.appiconset folder, 318

AppKit, 179

Apple developer program

Apple IDs, registering for, 10

choosing, 8-10

enrolling in, 8

iOS program, 9-10

Mac OS program, 9-10

membership categories, 9-10

Safari program, 9

Apple IDs, registering for, 10

Apple LLVM Compiler 3.0, 223

AppleScript, 241

Application and Foundation Kits, 7

applicationDidFinishLaunchingWithOptions method, 201

Applications folder, 41

apps

archiving, 321-324

iOS archives, 324

Mac archives, 322-323

building with actions, 150-159

iOS apps, 155-157

OS X apps, 151-154

bundles

asset catalogs, 318

definition of, 317

explained, 317-318

lproj files, 318

plist files, 319

precompiled header files (.pch), 319

reasons for using, 318

Instruments, 310

testbed apps. See also testbed apps

building on iOS, 78

building on OS X, 79

creating, 193-196

message syntax, 94-95

overview, 77-78

text fields, 78-94

ARC (automatic reference counting)

declared property attributes, 226-227

overview, 113, 225-227

archiving apps, 321-324

iOS archives, 324

Mac archives, 322-323

arguments

overview, 145

setting, 174

arrays, 315

accessing objects in, 218

creating, 215-217

enumerating, 215-217

iterating through, 206

reading and writing, 213

testing membership in, 217

arrayWithArray method, 210

arrayWithContentsOfFile method, 213

arrayWithContentsOfURL method, 213

arrayWithObject method, 210

arrayWithObjects method, 210

asset catalogs, 318

associative references, 250-251

adding, 251

getting and setting, 252

hiding in declared property, 252

removing, 254

asynchronous tasks, adding to queues, 289

atomicity, 137, 226

attributes of declared properties

accessor methods, 136

atomicity, 137

other attribute decorators, 137

overview, 133, 135

setter semantics, 137

writability, 136

automatic reference counting (ARC), 113, 225-227

@autoreleasepool directive, 228

__autoreleasing— variable qualifier, 227

autoreleasing variables, 228

Availability.h file, 319

B

BankAccount class, 26-28

base objects, overriding, 29

Base.lproj file, 318

battery usage, 310

binding (dynamic), 117

__block storage type modifier, 269

block variables, creating, 264-265

Block_copy() function, 269

Block_release() function, 269

blocks

compared to callback functions, 264

in Cocoa, 266

copying to heap, 269

creating as block variables, 264-265

creating from callback functions, 265

enumeration methods, 265-267

enumerateKeysAndObjectsUsingBlock:, 268

enumerateLinesUsingBlock:, 267-268

enumerateObjectsUsingBlock:, 268

overview, 259-260

try/catch blocks, 275-278

branches

creating, 50-56

overview, 47-48

breakpoints, 293, 297

breaking on conditions, 298-302

editing, 298-300

setting on actions, 160

building apps with actions, 150-159

iOS apps, 155-157

OS X apps, 151-154

bundles. See also packages

asset catalogs, 318

definition of, 317

explained, 317-318

lproj files, 318

plist files, 319

precompiled header files (.pch), 319

reasons for using, 318

Burroughs large systems, 132

business membership (developer program), 10

C

C language

control structures, 315

if statements, 315

repeat statements, 316

switch statements, 315

data types, 313

arrays, 315

enumerated type, 313

pointers, 314

struct, 314

development of, 24

The C Programming Language (2nd Edition) (Kernighan and Ritchie), 24, 313

C++, 24

calculate method, 133

callback functions, 260-261

compared to blocks, 264

creating blocks from, 265

calling methods, 104

callStackSymbols, 296

carat (^), 264

catalogs (asset), 318

@catch, 275-278

catching exceptions, 280

categories, 30

alternatives to, 240

compared to protocols, 239

compared to subclasses, 241-242

confining modifications to, 242

creating, 242-245

informal protocols, 246

when to use, 240

changes

discarding, 56

tracking, 52-55

checking out repositories, 60

choosing developer program, 8-10

class clusters, 183-184

@class directive, 74, 108, 117

class hierarchy, modifying, 241-242

class name, creating instance variables with, 117-119

classes, 25. See also protocols

abstract classes, 106

AppDelegate

.h files, 70-71

.m files, 71-73

associative references, 250-251

adding, 251

getting and setting, 252

hiding in declared property, 253

removing, 254

BankAccount, 26-28

categories, 240

alternatives to, 240

anonymous categories, 242-246

compared to protocols, 239

compared to subclasses, 241-242

confining modifications to, 242

creating, 242-245

informal protocols, 246

when to use, 240

class hierarchy, modifying, 241-242

collection classes, 112-114, 209-210. See also collections

creating

preparation, 98-99

with Xcode, 99-103

CurrencyConverter

convertCurrency: method, 191-193

convertUnits: method, 193

convertUnits:withFactor: method, 194-200

creating instance variables with class name, 117-119

creating instance variables with superclass name, 119-123

creating with Xcode, 99-103

CurrencyConverter.h file, 99-103

CurrencyConverter.m file, 104

designing, 190-191

history of, 98

init methods, 200-202

instance variables, creating with id, 114-117

declaring

basic class declaration, 106-107

forward references, 107-108

designing, 97-98

extensions, 245-246

Foundation framework

class clusters, 183-184

class groups, 180-182

mutability, 182-183

root classes, 180

turning into protocols, 181

instantiating, 111-112

ARC (automatic reference counting), 113

choosing context, 112-114

placing class instances in context, 112

methods

actions, 107

addObserver, 186

addObserverForName, 186

allObjects, 215

alloc, 35, 37-38, 113

anyObject, 218

applicationDidFinishLaunchingWithOptions, 201

arrayWithArray, 210

arrayWithContentsOfFile, 213

arrayWithContentsOfURL, 213

arrayWithObject, 210

calculate, 133

class methods, 35

class methods versus instance methods, 142-143

containsObject, 215

convertCurrency, 191-193

convertUnits, 193, 201

convertUnits:withFactor:, 194-200

dealloc, 113, 223

declaring, 34, 143-146

description, 104

dictionaryWithContentsOfFile, 214

dictionaryWithContentsOfURL, 214

dictionaryWithDictionary, 210

dictionaryWithObject, 212

dictionaryWithObjects, 212

didFinishLaunchingWithOptions, 244, 262

draw, 104

enumerateKeysAndObjectsUsingBlock, 260, 268

enumerateLinesUsingBlock, 260, 267-268

enumerateObjectsUsingBlock, 260, 268

exceptionWithName, 278

getReturnValue, 174-175

hiding, 29

implementing, 194-200

init methods, 38, 200-202

initWithBool, 142

initWithFactor, 201

instancesRespondToSelector, 176

invocationWithMethodSignature, 172

invoke, 175

invokeWithTarget, 175

keyEnumerator, 215

nextObject, 214

numberWithBool, 142

objectAtIndex, 218

objectEnumerator, 215

objectForKey, 215, 218

optional methods, 236

parameters, 36-37

postNotification, 185

postNotificationName, 185

removeObserver, 186

respondsToSelector, 176

return values, 174-175

returning multiple result values from, 112-114

reverseObjectEnumerator, 215

setArgument, 174

setByAddingObject, 214

setByAddingObjectsFromArray, 214

setByAddingObjectsFromSet, 214

setSelector, 174

setTarget, 173

setter semantics, 137

setWithArray, 214

setWithObjects, 215

setWithSet, 210

signatures, 36-37, 172

superclass methods, 104

syntax, 141

useTypeDefFunction

Pointer, 262

writeToFile, 213

writeToURL, 213-214

naming, 98-99

NSArray, 209-210

creating and enumerating, 215-217

enumerateObjectsUsingBlock: method, 268

iterating through, 206

NSAutoreleasePool, 228

NSDate, 208

NSDictionary

enumerateKeysAndObjectsUsingBlock: method, 268

overview, 209-210

NSEnumerationConcurrent, 266

NSEnumerationReverse, 267

NSEnumerator

methods, 214-215

NSEnumerator instances, creating, 215

overview, 256

NSError, 274-275

NSException, 272-274

NSNotification, 183

NSNotificationCenter, 185

NSNumber

getters, 192

overview, 183, 208

NSObject, 34, 179-180

NSOperationQueue, 287

NSProxy, 180

NSSet, 209-210, 268

NSString, 209, 267-268

subclasses

compared to categories, 241-242

pros and cons, 231-232

superclass methods, 104

cloning repositories, 60

clusters (class), 183-184

Cocoa frameworks, 179

errors, 277

views, 78

windows, 78

Cocoa Touch frameworks, 179

errors, 277

code property (NSError), 274

collections

accessing objects in, 218

advantages of, 205-207

arrays

creating, 215-217

enumerating, 215-217

reading and writing, 213

building from property lists at runtime, 209

collection classes, 112-114, 209-210

creating with literals, 212

creation methods, 210-212

dictionaries, reading and writing, 213-214

enumeration

NSEnumerator instances, 215

NSEnumerator methods, 214-215

mutable collections, 207

optimization, 211

overview, 205-207

in property lists, 207-209

sets, creating, 214

testing membership in, 217

colon (:), 145

color, setting for messages, 92-94

compiler directives

@autoreleasepool, 228

@catch, 275-278

@class, 74, 108, 117

#define, 66-67

definition of, 66

@dynamic, 139

@end, 74, 107

@finally, 275

#ifdef, 67

#ifndef, 67

@implementation, 74

#import, 68-69

#include, 68

@interface, 74

@optional, 236, 246

@protocol, 74, 108

@required, 236

@selector, 169

@synthesize, 130-132, 138

@try, 275-278

concurrency

definition of, 283

dispatch queues, 288

adding asynchronous tasks to, 289

designing with, 290

global concurrent dispatch queues, 288-289

GCD (Grand Central Dispatch), 285-286

implementing, 284

multicore processors, 283-284

queues

dispatch queues, 287

dispatch sources, 287

operation queues, 287-288

overview, 286

threads, 284-285

conditions, breaking on, 298-302

confining modifications to categories, 242

console logs

NSLog, 295-297

overview, 293-294

troubleshooting with, 294

viewing, 294

containsObject: method, 215

control structures, 315

if statements, 315

repeat statements, 316

switch statements, 315

Convert to Objective-C ARC command, 225

convertCurrency: method, 191-193

convertUnits: method, 193, 201

convertUnits:withFactor: method, 194-200

copying

blocks to heap, 269

method declarations, 143

Core Foundation framework, 180

counting references. See reference counting

Cox, Brad, 7

Cox, Brian J., 165, 179

CPU utilization, monitoring, 306-307

creating. See also declaring

actions

iOS projects, 155-157

OS X projects, 151-154

arrays, 215-217

associative references, 251

blocks

as block variables, 264-265

from callback functions, 265

categories, 242-245

classes

preparation, 98-99

with Xcode, 99-103

collections

with creation methods, 210-212

with literals, 212

iOS archives, 324

Mac archives, 322-323

method signatures, 172

NSEnumerator instances, 215

NSInvocation object, 172

sets, 214

testbed apps, 193-196

CurrencyConverter

convertCurrency: method, 191-193

convertUnits: method, 193

convertUnits:withFactor: method, 194-200

creating with Xcode, 99-103

CurrencyConverter.h file, 99

CurrencyConverter.m file, 104

designing, 190-191

history of, 98

init methods, 200-202

instance variables

creating with class name, 117-119

creating with id, 114-117

creating with superclass name, 119-123

cut back, 132

D

dangling pointers, 227

data abstraction, 24-25

data types, 313

arrays

iterating through, 206

overview, 315

dynamic typing, 190

enumerated type, 313

id, 114-117, 129

pointers, 314

primitive types, 205

SEL, 168-169

struct, 314

dealloc method, 113, 223

debug gauges, 305-306

monitoring CPU utilization, 306-307

monitoring energy, 308-309

monitoring memory utilization, 307-308

debugger

breakpoints, 293, 297

breaking on conditions, 298-302

editing, 298-300

console logs

NSLog, 295-297

overview, 293-294

troubleshooting with, 294

viewing, 294

documentation, 302

debugging, 302

debug gauges, 305-306

monitoring CPU utilization, 306-307

monitoring energy, 308-309

monitoring memory utilization, 307-308

debugger

breakpoints, 293, 297-302

console logs, 293-297

documentation, 302

with description method, 104

with Instruments app, 310

declared properties

adding, 201

attributes, 226-227, 253

declaring. See also creating

categories, 242-245

classes

basic class declaration, 106-107

forward references, 107-108

instance variables, 107, 111

methods, 34, 143

arguments, 145

method names, 144-145

return values, 143-144, 146-147

writing method declarations, 146

properties

attributes, 133

example, 130-133

memory management, 132

variables

basic variable declaration, 128-130

legacy instance variable declarations, 138

#define directive, 66-67

delegates, 264

Master-Detail Application template example, 232-235

overview, 233

description method, 104

design patterns, 149

designing

classes, 97-98

CurrencyConverter, 190-191

with queues, 290

Developer folder, 41

developer program

Apple IDs, registering for, 10

choosing, 8-10

enrolling in, 8

iOS program, 9-10

Mac OS program, 9-10

membership categories, 9-10

Safari program, 9

Developer Technical Support (DTS), 9

development of Git, 48

development of Objective-C, 7-8

dictionaries

accessing objects in, 218

reading and writing, 213-214

testing membership in, 217

dictionaryWithContentsOfFile method, 214

dictionaryWithContentsOfURL method, 214

dictionaryWithDictionary method, 210

dictionaryWithObject method, 212

dictionaryWithObjects method, 212

didFinishLaunchingWithOptions method, 244, 262

directives

@autoreleasepool, 228

@catch, 275-278

@class, 74, 108, 117

#define, 66-67

definition of, 66

@dynamic, 139

@end, 74, 107

@finally, 275

#ifdef, 67

#ifndef, 67

@implementation, 74

#import, 68-69

#include, 68

@interface, 74

@optional, 236, 246

@protocol, 74, 108

@required, 236

@selector, 169

@synthesize, 130-132, 138

@try, 275-278

discarding changes with Git, 56

disconnecting actions, 161

dispatch queues, 288

adding asynchronous tasks to, 289

designing with, 290

explained, 287

global concurrent dispatch queues, 288-289

dispatch sources, 287

distributed objects, 182

documentation for debugger, 302

domain codes (NSError), 274

domain property (NSError), 274

dot syntax, accessing properties with, 134-135

downloading Xcode, 41

draw method, 104

DTS (Developer Technical Support), 9

dynamic binding, 117

@dynamic directive, 139

dynamic typing, 190

dynamism, 273

E

Edit Breakpoint menu, 299

editing breakpoints, 298-300

encapsulation

overview, 25-28

variable declarations, 129-130

@end directive, 74, 107

energy, monitoring, 308-309

Energy Impact gauge, 308-309

enterprise program (developer program), 10

enumerated type, 313

enumerateKeysAndObjectsUsingBlock method, 260, 268

enumerateLinesUsingBlock method, 260, 267-268

enumerateObjectsUsingBlock method, 260, 268

enumeration,

arrays, 215-217

block enumeration methods, 265-267

enumerateKeysAndObjectsUsingBlock, 268

enumerateLinesUsingBlock, 267-268

enumerateObjectsUsingBlock, 268

collections

NSEnumerator instances, 215

NSEnumerator methods, 214-215

fast enumeration, 254-256

with NSEnumerator, 256

without NSEnumerator, 255

NSEnumerationConcurrent, 266

NSEnumerationReverse, 267

small objects, 267

error codes (NSError), 276

errors

in Cocoa and Cocoa Touch, 276-277

compared to exceptions, 272

NSError class, 274-275

overview, 271-272

evolution of Objective-C, 7-8

exceptions

catching, 280

compared to errors, 272

identifying, 277-278

NSException class, 272-274

overview, 271-272

throwing, 278-279

exceptionWithName method, 278

expressions, logging, 296

extensions, 30, 245-246

F

fast enumeration, 254-256

with NSEnumerator, 256

without NSEnumerator, 255

fields, text, 81

adding in iOS, 82-84

adding in OS X, 85-87

connecting to code in iOS, 88-91

connecting to code in

OS X, 91

sending messages to, 92-94

__FILE__ macro, 295

file system classes, 181

files

Availability.h, 319

creating dictionaries from, 214

.h files, 33, 66, 70-71

implementation files. See implementation files, defining classes in

lproj, 318

.m files, 33, 66, 71-73

main.m file, 69-70

missing files, 65

.pch files, 66

plist, 319

plist files, 66

precompiled header files (.pch), 319

prefix headers, 67-69

.rtf files, 65

.strings files, 65

writing arrays to, 213

.xib files, 65

@finally, 275

folders

AppIcon.appiconset, 318

Applications, 41

Developer, 41

Images.xcassets, 318

LaunchImage.launchimage, 318

forks, 47-48

for loops, adding to breakpoints, 298-302

forward references, 107-108

Foundation framework

classes

class clusters, 183-184

class groups, 180-182

root classes, 180

turning into protocols, 181

Core Foundation framework, 180

layers, 23-24

mutability, 182-183

notifications, 184-186

posting, 185

registering to receive, 186

removing observers, 186

values, 183-185

overview, 22, 179-180

__func__ macro, 295

functions. See also methods

Block_copy(), 269

Block_release(), 269

callback functions, 260-261

compared to blocks, 264

creating blocks from, 265

objc_getAssociatedObject, 251-252

objc_removeAssociatedObjects, 251

objc_setAssociatedObject, 250, 251, 254

typedef function pointer, 261-262

G

garbage collection, 222

GCD (Grand Central Dispatch), 285-286

getReturnValue method, 174-175

Git, 11, 50-56

discarding changes, 56

history of, 48

remote repositories, 58-60

tracking changes, 51-55

global concurrent dispatch queues, 288-289

Grand Central Dispatch (GCD), 285-286

groups of classes, 180-182

H

.h files, 33, 66, 70-71

headers

action headers, 159

.h files, 70-71

precompiled header files (.pch), 319

prefix headers, 67-69

heap, copying blocks to, 269

hiding

associative references in declared property, 253

methods, 29

history of Git, 48

history of Objective-C, 7-8, 249-250

hyphen (), 142

I

IBAction, 159

IBOutlet, 137

id data type, 114-117, 129

id variable, 35

identifying exceptions, 275-278

if statements, 315

#ifdef directive, 67

#ifndef directive, 67

imageset folders, 318

Images.xcassets folder, 318

@implementation directive, 74

implementation files, defining classes in

CurrencyConverter, 190-191

convertCurrency: method, 191-193

convertUnits: method, 193

init methods, 200-202

method implementation, 197-200

Testbed app, 193-196

implementing

concurrency, 284

methods, 194-200

object-oriented programming, 21-22

properties, 138-139

selectors, 170-171

#import directive, 68-69

#include directive, 68

informal protocols, 246

inheritance, 29-30

init methods, 38, 200-202

initializers, 37-38

initializing objects, 37-38

initWithBool method, 142

initWithFactor method, 201

inline function pointers, 261

instance methods, versus class methods, 142-143

instance variables. See also associative references

compared to properties, 127

creating for CurrencyConverter

with class name, 117-119

with id, 114-117

with superclass name, 119-123

declaring

explained, 107, 111

legacy instance variable declarations, 138

visibility, 123

instances

overview, 25

testing whether instance can respond to selector, 175-176

instancesRespondToSelector method, 176

instanceType keyword, 36

instantiating classes, 111-112

ARC (automatic reference counting), 113

choosing context, 112-114

placing class instances in context, 112

Instruments, 310

Interface Builder, selectors with, 171

@interface directive, 74

interprocess communication (IPC), 182

invocationWithMethodSignature method, 172

invoke method, 175

invokeWithTarget method, 175

invoking NSInvocation object, 175

iOS developer program, 9-10

iOS projects

actions

building projects with, 155-157

OS X versus iOS, 159-161

iOS archives, creating, 324

project files, 65-66

structure of, 64

testbed apps

adding text fields, 82-84

building, 78

connecting text fields to code, 89-91

creating, 193-196

message syntax, 94-95

sending messages to text fields, 92-94

IPC (interprocess communication), 182

iterating through arrays, 206

ivars. See instance variables

J-K

Jobs, Steve, 7

Kay, Alan, 165

Kernighan, Brian W., 24

keyEnumerator method, 215

keywords

instanceType, 36

strong, 226

unsafe_unretained, 227

weak, 226

L

language services, 182

LaunchImage.launchimage folder, 318

layers (frameworks), 23-24

legacy instance variable declarations, 138

__LINE__ macro, 295

literals, creating collections with, 212

localization, lproj files, 318

locks, synchronizing with, 287

logs

NSLog, 295-297

overview, 293-294

troubleshooting with, 294

viewing, 294

loops, for loops, 298-302

Love, Tom, 7, 165, 179

lproj files, 318

M

.m files, 33, 66, 71-73

Mac archives, creating, 322-323

Mac OS developer program, 9-10

macro definition directive, 66-67

macros, logging, 295

main.m file, 69-70

managing memory. See memory management

manual reference counting, 222-225

membership categories (developer program), 9-10

membership in collections, testing, 217

memory leaks, 306, 310

memory management

autoreleasing variables, 228

blocks, copying to heap, 269

garbage collection, 222

for objects, 132

overview, 221-222

reference counting

ARC (automatic reference counting), 225-227

explained, 222

manual reference counting, 222-225

variable qualifiers, 227

memory utilization, monitoring, 307-308

messages

accessing properties with, 133

adding to breakpoints, 298-300

color, setting, 92-94

message syntax, 94-95

nesting, 36

overview, 33, 165-166

receivers, 166

release, 224

retain, 224, 228

selectors

creating from string, 169-170

creating with @selector, 169

implementing, 170-171

with Interface Builder, 171

overview, 166

performSelector, 169-171

SEL data type, 168-169

setting, 174

testing whether instance can respond to selector, 175-176

sending to text fields, 92-94

signatures, creating, 172

simple example, 33-34

structure of, 92

methods. See also functions; protocols

accessors

creating with @synthesize, 138

overview, 28, 136, 226

actions, 107

addObserver, 186

addObserverForName, 186

allObjects, 215

alloc, 35, 37-38, 113

anyObject, 218

applicationDidFinishLaunchingWithOptions, 201

arrayWithArray, 210

arrayWithContentsOfFile, 213

arrayWithContentsOfURL, 213

arrayWithObject, 210

calculate, 133

class methods, 35

class methods versus instance methods, 142-143

containsObject, 215

convertCurrency, 191-193

convertUnits, 193, 201

convertUnits:withFactor:, 194-200

dealloc, 113, 223

declaring, 34, 143

arguments, 145

method names, 144-145

return values, 143-144, 146-147

writing method declarations, 146

description, 104

dictionaryWithContentsOfFile, 214

dictionaryWithContentsOfURL, 214

dictionaryWithDictionary, 210

dictionaryWithObject, 212

dictionaryWithObjects, 212

didFinishLaunchingWithOptions, 244, 262

draw, 104

enumerateKeysAndObjectsUsingBlock, 260, 268

enumerateLinesUsingBlock, 260, 267-268

enumerateObjectsUsingBlock, 260, 268

exceptionWithName, 278

getReturnValue, 174-175

hiding, 29

implementing, 194-200

init methods, 38, 200-202

initWithBool, 142

initWithFactor, 201

instancesRespondToSelector, 176

invocationWithMethodSignature, 172

invoke, 175

invokeWithTarget, 175

keyEnumerator, 215

nextObject, 214

numberWithBool, 142

objectAtIndex, 218

objectEnumerator, 215

objectForKey, 215, 218

optional methods, 236

parameters, 36-37

postNotification, 185

postNotificationName, 185

removeObserver, 186

respondsToSelector, 176

return values, getting, 174-175

returning multiple result values from, 112-114

reverseObjectEnumerator, 215

setArgument, 174

setByAddingObject, 214

setByAddingObjectsFromArray, 214

setByAddingObjectsFromSet, 214

setSelector, 174

setTarget, 173

setter semantics, 137

setWithArray, 214

setWithObjects, 215

setWithSet, 210

signatures, 36-37, 172

superclass methods, calling, 104

syntax, 142

useTypeDefFunctionPointer, 262

writeToFile, 213

writeToURL, 213-214

missing files, 65

modifying class hierarchy, 241-242

monitoring

CPU utilization, 306-307

energy, 308-309

with Instruments app, 310

memory utilization, 307-308

multicore processors, 283-284

multiple result values, returning from methods, 112-114

mutability, 182-183

mutable classes, 182-183

mutable collections, 207

MyApp-Info.plist file, 319

N

name property (NSException), 274

Name value (NSNotification), 183

names

class name, creating instance variables with, 117-119

method names, 144-145

superclass name, creating instance variables with, 119-123

naming classes, 98-99

nesting messages, 36

NeXT, 7

nextObject method, 214

NeXTSTEP, 7

nil value, 212

notifications, 182-186

posting, 185

registering to receive, 186

removing observers, 186

values, 183-185

NSArray class, 209-210

creating and enumerating, 215-217

enumerateObjectsUsingBlock: method, 268

iterating through, 206

NSAutoreleasePool class, 228

NSDate class, 208

NSDictionary class

enumerateKeysAndObjectsUsingBlock: method, 268

overview, 209-210

NSEnumerationConcurrent class, 266

NSEnumerationReverse class, 267

NSEnumerator class, 256

methods, 214-215

NSEnumerator instances, creating, 215

NSError class, 274-275

NSException class, 272-274

NSInvocation object

creating, 172

invoking, 175

overview, 172

properties, 173-175

NSLog class, 295-297

NSLogv class, 295

NSNotification class, 183

NSNotificationCenter class, 185

NSNumber class

getters, 192

overview, 183, 208

NSObject class, 34, 179-180

NSOperationQueue class, 287

NSProxy class, 180

NSSet class

enumerateObjectsUsingBlock: method, 268

overview, 209-210

NSString class

enumerateLinesUsingBlock: method, 267-268

overview, 209

NSStringFromClass, 296

NSStringFromSelector class, 296

numberWithBool method, 142

O

objc_getAssociatedObject function, 251-252

objc_removeAssociatedObjects function, 251

objc_setAssociatedObject function, 250, 251, 254

Object Oriented Programming: An Evolutionary Approach (Cox), 179

Object value (NSNotification), 184

objectAtIndex method, 218

objectEnumerator method, 215

objectForKey method, 215, 218

object-oriented programming

accessors, 28

classes, 25

data abstraction, 24-25

encapsulation, 25-28

frameworks

layers, 23-24

overview, 22

implementing, 21-22

inheritance, 29-30

instances, 25

messages

nesting, 36

overview, 33

simple example, 33-34

methods

class methods, 35

declaring, 34

parameters, 36-37

signatures, 36-37

objects

allocating, 37-38

initializing, 37-38

overview, 21

projects, 22

variables

strongly typed variables, 35-36

weakly typed variables, 35-36

objects. See also classes

allocating, 37-38

associative references, 250-251

adding, 251

getting and setting, 252

hiding in declared property, 253

removing, 254

base objects, overriding, 29

collections

accessing objects in, 218

advantages of, 205-207

arrays, creating, 215-217

arrays, reading and writing, 213

building from property lists at runtime, 209

collection classes, 209-210

creating with literals, 212

creation methods, 210-212

dictionaries, reading and writing, 213-214

enumeration, 214-217

mutable collections, 207

optimization, 211

overview, 205-207

in property lists, 207-209

sets, creating, 214

testing membership in, 217

debugging, 104

delegates

Master-Detail Application template example, 232-235

overview, 233

distributed objects, 182

initializing, 37-38

memory management. See memory management

NSInvocation

creating, 172

invoking, 175

overview, 172

properties, 173-175

receivers, 166

selectors

creating from string, 169-170

creating with @selector, 169

implementing, 170-171

with Interface Builder, 171

overview, 166

performSelector, 169-171

SEL data type, 168-169

setting, 174

testing whether instance can respond to selector, 175-176

observers, removing, 186

operating system services, 181

operation queues, 287-288

optimization for collections, 211

@optional directive, 236, 246

optional methods (protocols), 236

OS X projects

actions

building projects with, 151-154

OS X versus iOS, 159-161

project files, 65-66

structure of, 64-65

testbed apps

adding text fields, 82-88

building, 78-81

connecting text fields to code, 88

message syntax, 94-95

sending messages to text fields, 92-94

overriding base objects, 29

P

packages, definition of, 317

packaging apps, 321-324

iOS archives, 324

Mac archives, 322-323

paradigms, 149

parameters (method), 36-37

pasting method declarations, 143

.pch files (precompiled header files), 66, 319

performSelector, 169-171

personal membership (developer program), 9-10

placing class instances in context, 112

plist files, 66, 319

plus sign (+), 35, 142

pointers, 314

dangling pointers, 227

inline function pointers, 261

typedef function pointer, 261-262

posting notifications, 185

postNotification method, 185

postNotificationName method, 185

precompiled header files (.pch), 66, 319

predicates, 181

prefix headers, 67-69

__PRETTY_FUNCTION__ macro, 295

primitive types, 205

private variables, 123

project info, 12

projects

creating, 16, 43-45

files

.h files, 70-71

.m files, 71-73

main.m file, 69-70

prefix headers, 67-69

iOS projects, 64

object-oriented projects, 22

OS X projects, 64-65

project files, 65-66

project info, 12

source code control

branches, 47-48, 50-56

Git, 50-56

overview, 42-47

repository tips, 48-49

structure of, 63

targets, 12

workspace, 12-16

properties

accessing

with dot syntax, 134-135

with message syntax, 133

adding to code, 133

attributes, 133, 135

accessor methods, 136

atomicity, 137

other attribute decorators, 137

setter semantics, 137

writability, 136

compared to instance variables, 127

declared properties

adding, 201

attributes, 226-227, 253

declaring

attributes, 133

example, 130-133

memory management, 132

implementing, 138-139

NSInvocation object, 173-175

property lists

building collections from at runtime, 209

collections in, 207-209

writing dictionaries as, 213

strong, 133

property lists

building collections from at runtime, 209

collections in, 207-209

writing dictionaries as, 213

protected variables, 123

@protocol directive, 74, 108

protocols, 30

compared to categories, 239

informal protocols, 246

Master-Detail Application template example, 232-235

optional methods, 236

overview, 106, 232-233

turning classes into, 181

public variables, 123

Q

qualifiers, variable qualifiers, 227

queues

dispatch queues, 287

adding asynchronous tasks to, 289

designing with, 290

explained, 287

global concurrent dispatch queues, 288-289

dispatch sources, 287

operation queues, 287-288

overview, 286

R

reading

arrays, 213

dictionaries, 213-214

reason property (NSException), 274

receivers, 166

receiving notifications, 186

reference counting

ARC (automatic reference counting)

declared property attributes, 226-227

explained, 113, 225-227

explained, 222

manual reference counting, 222-225

references

associative references, 250-251

adding, 251

getting and setting, 252

hiding in declared property, 253

removing, 254

forward references, 107-108

reference counting

ARC (automatic reference counting), 113

explained, 222

manual reference counting, 222-225

registering

for Apple IDs, 10

for notifications, 186

release messages, 224, 228

remote repositories, 58-60

removeObserver method, 186

removing

actions, 161

associative references, 254

observers, 186

repeat statements, 316

repositories

checking out, 60

cloning, 59

remote repositories, 58-60

tips, 48-49

@required directive, 236

respondsToSelector method, 176

retain messages, 224, 228

return values

getting, 174-175

overview, 143-144, 146-147

returning multiple result values from methods, 112-114

reverseObjectEnumerator method, 215

Rhapsody, 7

Ritchie, Dennis M., 24

root classes (Foundation framework), 180

.rtf files, 65

runtime, 167-168

S

Safari developer program, 9

Sams Teach Yourself C in 21 Days (Jones and Aitkin), 313

scripting methods, 182

SEL data type, 168-169

@selector directive, 169

selectors

creating from string, 169-170

creating with @selector, 169

implementing, 170-171

with Interface Builder, 171

overview, 166

performSelector, 169-171

SEL data type, 168-169

setting, 174

testing whether instance can respond to selector, 175-176

sending messages to text fields, 92-94

setArgument method, 174

setByAddingObject method, 214

setByAddingObjectsFromArray method, 214

setByAddingObjectsFromSet method, 214

sets

accessing objects in, 218

creating, 214

testing membership in, 217

setSelector method, 174

setTarget method, 173

setter semantics, 137, 226

setWithArray method, 214

setWithObjects method, 215

setWithSet method, 210

signatures (method)

creating, 172

overview, 36-37, 172

Simula, 24

small-scale enumeration, 267

Smalltalk, 24, 166

source code control

branches

creating, 50-56

overview, 47-48

Git, 50-56

discarding changes, 56

history of, 48

tracking changes, 52-55

overview, 42-47

remote repositories, 58-60

repository tips, 48-49

Subversion, 58

square brackets ([]), 94

statements

if, 315

repeat, 316

switch, 315

static typing, 117-122

step-by-step conversion routine, building, 194-200

strings, 169-170

.strings files, 65

stringWithUTF8String, 296

strong keyword, 226

strong property, 133

__strong— variable qualifier, 227

strongly typed variables, 35-36

struct type, 314

subclasses

compared to categories, 241-242

pros and cons, 231-232

Subversion

remote repositories, 58-60

on single computer, 58

superclass methods, calling, 104

superclass name, creating instance variables with, 119-123

switch statements, 315

at symbol (@), 74

synchronizing with locks, 287

@synthesize directive, 130-132, 138

T

targets

overview, 12

setting, 173

tasks, adding to queues, 289

testbed apps

building on iOS, 78

building on OS X, 79

creating, 193-196

message syntax, 94-95

overview, 77-78

text fields, 81

adding in iOS, 82-84

adding in OS X, 85-87

connecting to code in iOS, 89-91

connecting to code in OS X, 91

sending messages to, 92-94

testing

membership in collections, 217

whether instance can respond to selector, 175-176

text fields, 78

adding in iOS, 82-84

adding in OS X, 85-87

connecting to code in iOS, 89-91

connecting to code in OS X, 91

sending messages to, 92-94

threading methods, 182

threads, concurrency, 284-285

throwing exceptions, 278-279

time-saving features

associative references, 250-251

adding, 251

getting and setting, 252

hiding in declared property, 253

removing, 254

fast enumeration, 254-256

with NSEnumerator, 256

without NSEnumerator, 255

overview, 249-250

Torvalds, Linus, 48

tracking changes with Git, 52-55

troubleshooting. See also debugging

errors

in Cocoa and Cocoa Touch, 277

compared to exceptions, 272

NSError class, 274-275

overview, 271-272

exceptions

catching, 280

compared to errors, 272

identifying, 275-278

NSException class, 272-274

throwing, 278-279

@try, 275-278

try/catch blocks, 275-278

typedef function pointer, 261-262

types, 313

arrays

iterating through, 206

overview, 315

dynamic typing, 190

enumerated type, 313

id, 114-117, 129

pointers, 314

primitive types, 205

SEL, 168-169

struct, 314

U

UIKit, 179

university team membership (developer program), 10

unsafe_unretained keyword, 227

__unsafe_unretained— variable qualifier, 227

URLs

creating dictionaries from, 214

URL classes, 182

writing arrays to, 213

writing dictionaries to, 214

userInfo property

NSError class, 274

NSException class, 274

userInfo value (NSNotification), 185

useTypeDefFunctionPointer method, 262

V

value objects, 180

variable qualifiers, 227

variables

autoreleasing variables, 228

block variables, 264-265

declaring

basic variable declaration, 128-130

legacy instance variable declarations, 138

id, 35

instance variables. See also associative references

compared to properties, 127

creating for CurrencyConverter, 114-117

creating for CurrencyConverter with class name, 117-119

creating for CurrencyConverter with superclass name, 119-123

declaring, 107, 111

visibility, 123

strongly typed variables, 35-36

variable qualifiers, 227

weakly typed variables, 35-36

versions of Xcode, 41-42

viewing console logs, 294

views (Cocoa), 77

visibility of instance variables, 123

W

weak keyword, 226

__weak— variable qualifier, 227

weakly typed variables, 35-36

windows (Cocoa), 77

workspace, 12-16

writability, 136

writeToFile method, 213

writeToURL method, 213-214

writing

arrays, 213

dictionaries, 213-214

method declarations, 146

X-Y-Z

Xcode

classes, creating, 99-103

downloading, 41

overview, 11, 41-42

projects, 41-42

creating, 17, 43-45

iOS projects, 64

OS X projects, 64-65

project files, 65-66

project info, 12

structure of, 63

source code control

branches, 47-48, 50-57

Git, 50-56

overview, 42-47

remote repositories, 58-60

repository tips, 48-49

Subversion, 58

targets, 12

versions, 41-42

workspace, 12-16

Xerox PARC, 165

.xib files, 65

XML support classes, 181

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

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