# (asterisk), 37
(backslash) in #define statement, 231
? (conditional operator), 123
— decrement operator, 282, 286–288
# directive, 512
== (double equal sign), if statement and, 102
++ increment operator, 282, 286–288
# indirection operator, 273
&& (logical AND operator), 102–103
|| (logical OR operator), 102–103
# operator, 234
## operator, 235
% (percent) character, 22
modulus operator, 100
& operator, pointers and, 273
# pound sign, preprocessor and, 227
= (single equal sign), if statement and, 102
~(tilde), home directory, 374
absolute pathnames, 374
abstract protocols, 222
accumulator, 63
address book
AddressCard class, 340–342
arrays, sorting, 356–360
dealloc method, 343–350
deleting names, 353–356
name lookup, 350–353
release method, 343–350
address operator, pointers and, 273
AddressBook class
implementation file, 529–531
interface file, 526
AddressCard class, 340–342
implementation, 526–528
interface file, 525–526
addresses, memory
indirection operator, 292
pointers and, 291
adopting protocols, 219–220
alignment, 80
allocating memory, 139–145, 156–157
primes array, 339
allocF class method, as entry, 197–199
AND operator (&), 102–103
answers to exercises, 533
AppKit (Application Kit), 455
Apple
development environment, Cocoa, 1
event descriptors, NSAppleEventDescriptor.h header file, 515
AppleScript
header files for, 519
scripts, NSAppleScript.h header file, 515
Application Kit framework, 307
archiving, 455
basic data types, 438–440
custom archive
methods, 444–448
NSData object, 444–448
definition of, 427
Foundation framework and, 307
key, 441–443
keyed archive, 441–445
definition of, 441
with NSArchiver class, 431–433
NSArchiver.h header file, 515
with plists, 427–430
argc argument, main function and, 298
argument type declaration, functions and, 257–258
arguments
argc argument, main function and, 298
argv argument, main function and, 298
comma separator, 22
command-line arguments, 19, 297–300
functions and, 253–255
methods
arguments, 34
local variables, 136
multiple arguments in, 130–135
no argument name, 133
parameters, 19
zone argument, 422
argv argument, main function and, 298
arithmetic
conversions, 488–489
integer arithmetic, 56–58
conversions, 59–61
modulus operator, 58–59
type cast operator, 61–62
NSDecimal.h header file, 516
NSDecimalNumber.h header file, 516
operators, 481
associative properties, 54
binary, 54
bit operators, 65–69
precedence, 54
unary minus operator, 58
array elements, 246
initialization elements, 249
initializing, 248–249
character arrays, 249
terminating null character and, 250
declaring, 247
#define statements and, 229
defining, 246–248
number of elements, 249
unions and, 293
definition of, 246
elements
passing functions to, 258–259
passing methods to, 258–259
functions, passing to, 258–259
immutable arrays, 335
linear arrays, 250
manipulating, 246–248
methods, passing to, 258–259
multidimensional arrays, 250–252, 471–472
mutable arrays, 335
objects, 335–360
NSArray.h header file, 515
one-dimensional arrays, 250
operators and, 485
pointers and, 280–283
pointers to, 486–487
single-dimension, 470
sorting, address book project, 356–360
of structures, 267
two-dimensional arrays, 250–251
elements, 250
matrixes and, 250
variable-length, 471
arrayWithCapacity: method, 337
arrayWithObjects: method, 337
ASCII format of character storage, 110
assignment operators, 62–65, 483
associative properties, arithmetic operators, 54
asterisk (*), 37
attribute dictionary, 375
auto keyword, 199–200
automatic local variables, 254
declaring, 199–200
automatic variable, 455
keyword auto, 455
autorelease pool, 317–320, 399–400, 455
debugging, NSDebug.h header file, 516
NSAutoreleasePool.h header file, 516
practice project, 411–413
basic data types, 468–469
binary arithmetic operators, 54
binding, dynamic binding, 173, 177, 456
bit fields, 270–272
Bitwise AND, 66
Bitwise Exclusive-OR, 66–67
Bitwise Inclusive-OR, 66
left shift, 67
ones complement, 67
right shift, 67–69
bitfield, 455
Bitwise AND operator, 66
Bitwise Exclusive-OR operator, 66–67
Bitwise Inclusive-OR operator, 66
bitwise operators, 482–483
blank spaces, operators and, 105
blocks
enumerated data types, 204
of statements, 79
books for further readin g
C programming language, 534
Cocoa, 535
Objective-C, 533–534
Bool data type, 69
BOOL special type, 122
Boolean variables, 119–123
brackets, 26
switch statement and, 116
buffer, 378
Build menu, Project Builder, 14
built-in values
NO, 122
YES, 122
byte swapping, NSByteOrder.h header file, 516
C language in relation to Objective-C language, 300
C programming language
books for further reading, 534
resources for further information, Web sites, 534
C-style strings (C strings), 285, 320
calling functions, 493–494
calls, routines, 19
case sensitivity, 32
categories, 156, 211–213, 216–217, 456
adding new, 212
definition of, 211
instance variables and, 216
master class definition file, 216
methods
adding, 217
defining, 213
overriding, subclassing and, 216
new, 212–213
number allowed, 216
object/category named pairs, 217
overriding methods, 216
posing and, 219
protocols, adopting, 222
subclassing and, 216
cells, memory, 291
char characters, unichar characters and, 320
char data type, 47–51
character arrays, 249–250
initialization, 286
pointers and, 286
terminating null character and, 250
character constants, 466
escape sequences, 466
wide, 466
character sets, NSCharacterSet.h header file, 516
character strings, 250, 320, 456
constants, 467
concatenation, 467
multibyte characters, 467
objects, 467
wide, 467
pointers to, 284–285
character variable operator, reading operators into, 113
character variables, unsigned, 208
characters
as signed quantities, 207
character arrays, 249–250
character storage, ASCII format, 110
constant character string object, 321
digraphs, 461
newline, 19
null character, 459
terminating null character, 250
Unicode character, 460
universal character names, 462
charPtr variable, 275–276
@class directive, 157–160
child processes, NSTask.h heade rfile, 520
class message, 185
class objects, 456
class variables, class definition, 495–496
class.h files, 127
classes, 456
abstract classes, 173
clusters, 456
AddressBook class
implementation file, 529–531
interface file, 526
implementation file, 526–528
interface file, 525–526
Calculator class, 110
categories, 156
defining, 498–499
class definition, 494
implementation section, 496–497
instance variables, 495
interface section, 495
method declaration, 495–496
method definition, 497–498
composite class, 456
copy method, adding, 421–423
declarations, @interface section, 127
description, NSClassDescription.h header file, 516
extending, inheritance and, 152–164
Foundation string class, 238
Fraction class, 28, 97, 183, 186
implementation file, 522–525
interface file, 521–522
grandchild, 149
inheritance and, extending classes and, 152–164
initializing, 191–192
designated initializer, 192
initialize method, 193
methods, 192
message expressions, 501–502
messages, 26
methods, 197
adding, 152–164
NSArchiver class, 431–433
archiving with, 431–433
NSCountedSet, 368
NSData, 378–380
NSMutableString, 323
NSNumber, 315
NSProcessInfo, 388–392
NSUnarchiver class, program execution, 432
object definition, 500–501
object ownership, 161–164
objects, manipulation of, 300–301
Point class, 188
questions about, 185–188
receivers, 26
Rectangle class, 187–188
root, 147
storage class, 489
concrete subclass, 456
superclass, 460
clauses, else clause, 105–106
clusters, 456
books for further reading, 535
frameworks, Application Kit, 455
resources for further information, Web sites, 535
collections, 456
colon (:), 123
command-line arguments, 19, 297–300
commas in arguments, 22
comments in code, 14, 18–20, 464
debugging and, 18
Project Builder, 14
compare method, 319
compiler directives, 462
compilers
gcc, 457
interface files, 128
compiling
Macs and, 16–17
Project Builder, 10–15
Terminal window, 8–10
MinGW, 16
Complex data type, 69
composite class, 456
composite objects, 223–224
compound relational expressions, forma tion of, 103
compound relational test, 102–105
compound statements, 502
break, 503
continue, 503
do, 503
for, 503
goto, 504
if, 504
null, 505
return, 505
switch, 505–506
while, 506
concatenation of character string con stants, 467
concrete subclass, 456
conditional compilation
debugging and, 240
definition of, 238
preprocessor and, 238–239
conditional operator, 123–124, 483–484
as ternary operator, 123
else if clause and, 124
parentheses and, 124
conforming, 456
to protocols, 219
conformTo method, protocols and, 221
const keyword, 477
const variable, 200
constant character string object, 321
constant character strings, 456
C-style strings, 285
pointers and, 285–286
constant expressions, 47, 480–481
constants, 47
character constants, 466
escape sequences, 466
wide, 466
character string constants, 467
concatenation, 467
multibyte characters, 467
objects, 467
wide, 467
enumeration constants, 467
floating, hexadecimals, 49
integers, 464–465
conversions
arithmetic, 488–489
data type conversions, 206–208
data types, 488–489
floating-point numbers, 59–61
integers, 59–61
convertToNum method, 97–99
cookies
NSHTTPCookie.h header file, 517
NSHTTPCookieStorage.h header file, 517
coordinates
NSGeometry.h header file, 517
Point class and, 156
copy method, 416–418
classes, adding to, 421–423
Fraction class, adding to, 421–423
immutable object and, 425
copying
copy method, immutable object and, 425
deep copy, 418–420
elements, 420
files, program for, 388–392
fractions, 421–423
mutable copy, 416–418
objects, 415–418
getter method and, 424–425
setter methods and, 424–425
shallow copy, 418–420
count class method, as entry, 197–199
counting references. See reference counting
Cox, Brad J., 1
creation methods, NSNumber object, 318
custom archives, 444–448
CygWin system
download site, 536
Foundation framework, 307, 311–313
data encapsulation, 42–45, 456
data type conversions, 206–207
sign extension, 207–208
steps involved, 206
data type int, 48
data types, 47
archiving, 438–440
decoding, 438–440
encoding, 438–440
Bool, 69
char, 47–51
signed char variable, 208
Complex, 69
derived, 470
arrays, 470–472
pointers, 475–476
structures, 472–474
unions, 474–475
double, 47–49
enum keyword, 201–204
float, 47–49
dynamic binding and, 180–181
static typing and, 182–183
Imaginary, 69
modifiers, 477
qualifiers, 51–53
storage sizes, 48
dataValue variable, 181
dates
NSCalendarDate.h header file, 516
NSDateFormatter.h header file, 516
dealloc method, address book project and, 343–350
debugging, comments and, 18
debugging statements, 240
decimal arithmetic, NSDecimalNumber.h header file, 516
declarations, 468
classes, @interface section, 127
declaring methods, 35
decoding
basic data types, 438–440
NSArchiver.h header file, 515
NSCoder.h header file, 516
objects, 434
methods, 433–438
writing, 433–438
#define statement, 227–229, 507–509
(backslash) character, 231
arguments, 231
arrays and, 229
constant values and, 229
defined names, 229–233
macros, 232–233
# operator and, 234
## operator and, 235
placement, 228
preprocessor and, 227–229
syntax, 228
defined names, 229–233
defining methods, 35
deleteCharactersInRange: method, 332
denominator integer instance variable, 97
derived data types, 470
arrays
multidimensional, 471–472
single dimension, 470
variable-length, 471
pointers, 475–476
structures, 472–474
unions, 474–475
designated initializer, 192, 456
development environments
Cocoa, 1
GNUstep, 1
LinuxSTEP, 1
NEXTSTEP, 1
ONESTEP, 1
dictionaries, 456
attributes, 375
enumerations, 362–365
immutable, 361
keys, 360
mutable, 361
dictionary objects, 360–365
NSDictionary.h header file, 517
digraph characters, 461
@class, 157–160
@private directive, 194
@protected directive, 194
@protocol directive, 221
@public directive, 194
@selector directive, 186
instance variables, scope control, 193–194
preprocessor, 507
#, 512
#define, 507–509
#error, 509
#if, 509–510
#ifdef, 510
#ifndef, 510
#import, 511
#include, 511
#line, 511
#pragma, 512
#undef, 512
predefined, 512
directories
contents, enumerating, 382–384
include file directory, Unix systems and, 237
NSFileManager methods, 380–381
NSPathUtilies.h header file, 518
root directory, 374
—(tilde), 374
directory management, NSFileManager, 374–384
dispatch tables, 291
Distributed Objects, 456
distributed objects
NSConnection.h header file, 516
NSDistantObject.h header, 517
NSDistributeNotificationCenter.h header
file, 517
NSPortCoder.h header file, 518
NSPortMessage.h header, 519
doesNotRecognize method, 186
domains, NSNetServices.h header file, 518
dot operator, 261
double data type, 47–49
downloads
CygWin, 536
gcc, 536
GNUstep, 536
LinuxSTEP, 536
MinGW, 536
NSURLHandle.h header file, 520
dynamic binding, 173, 177, 180–181, 456
argument return and, 183–184
methods for working with, 185
value type return and, 183–184
elements, copying, 420
#elif preprocessor statement, 240–241
else clause, 105–106
else if clause, conditional operator and, 124
else if statement, 107–110, 113–115
n-valued logic decision and, 107
#else statement, 238–240
encapsulation, 457
encoding
basic data types, 438–440
NSArchiver.h header file, 515
NSCoder.h header file, 516
objects, 434
methods, 433–438
writing, 433–438
#endif statement, 238–240
enumerated data types, 476
blocks and, 204
definition of, 191
enum keyword, 201–204
enumeration
directory contents, 382–384
constants, 467
dictionaries, 362–365
identifier, 201–204
NSEnumerator.h. header file, 517
#error directive, 509
errors, NSError.h header file, 517
escape sequences, 466
event handlers, NSAppleEventManager.h header file, 515
exception handling, NSException.h header file, 517
exercise answers, 533
exponents, floating-point values, 49
expressions, 477
compound relational expressions, 103
constant expressions, 47, 480–481
lvalues, 477
message expressions, 458, 501–502
operators, 477–480
extending classes, inheritance and, 152–164, 171–173
Extensible Markup Language (XML), 460
extensions, filenames, 9
external global variable, 195
external variable
definition, 195
extern keyword, 195–198
static keyword, 197–199
external variables, extern keyword, 195
factory objects, 457
Fibonacci numbers, 247–248
fields
bit fields, 270–272
specification, 272
file management
NSFileManager, 374–384
NSFileManager.h header, 517
filename extensions, 9
files
class.h, 127
copying, program for, 388–392
file operations, 392–397
header files, 457
implementation files, Fraction.m, 128
include files, 238
float.h, 238
limits.h, 238
string.h, 238
linking, 373
local files, quotes, 129
master class definition file, categories, 216
naming, 9
NSFileManager methods, 374
opening, 373
pathnames, 374
filters, NSProtocolChecker.h header file, 519
float data type, 47–49
floating-point constants, 49, 465–466
hexadecimals, 49
scientific notation, 49
floating-point numbers, 21
conversions, 59–61
for loops, execution order, 77
loop variants, 84–85
nested loops, 82–84
terminal input, 80–82
formal protocols, 457
format strings, 23
forwarding, 151
messages, 457
archiving and, 307
array objects, 335–360
CygWin system, 311–313
Foundation library, NSLog function, 321–323
gcc, Mac, 311
GNUstep and, 311–313
headers, 515–520
initialization methods and, 192
introduction, 307
NSObject root class, message forwarding and, 189
Mac documentation, 308
methods
copy method, 416–418
mutableCopy method, 416–418
MinGW system and, 311–313
NSCountedSet class, 368
number objects, 315–320
object collections, 456
Project Builder and (Mac), 310–311
protocols and, 219
resources for further information, Web sites, 535
root object, 313
string objects, 320–335
Terminal and, Mac, 311
typedef statement and, 205
Foundation string class, 238
Foundation.h header file, 515
Fraction class, 28, 97, 183, 186
class method
allocF class method, 197–199
count class method, 197–199
copy method, adding, 421–423
implementation file, 522–525
interface file, 521–522
methods, converToNum method, 97–99
fractions, copying, 421–423
frameworks, 457. See also Application Kit framework; Foundation framework
program development and, 2
free method, overriding, 169–171
Free Software Foundation
gcc, 457
GNUStep, 457
function pointers, 494
functions, 252–253, 258, 457, 492
argument type declaration, 257–258
arguments, 253–255
arrays, passing, 258–259
definitions, 492–493
local variables, 253–255
argc arguments and, 298
argv arguments and, 298
multidimensional array element, passing, 259–260
NSHomeDirectory, 387
NSLog, 321–323
NSPathUtilities.h, 385
NSTemporaryDirectory, 386
path utilities, 388
to arrays, passing, 283–284
as argument, 291
dispatch tables, 291
returning as result, 278–279
printMessage, 252–253
prototypes, declaring, 257
qsort function, 291
results, returning, 255–256
return type declaration, 256–258
sign, 107
storage class, 490
values, returning, 255–256
download site, 536
Foundation framework and (Mac), 311
gdb debugging tool, 457
generic pointer type, id type, 301
getter methods, 424–425
getter routine, 424–425
getters, 44
global structure definition, 265
global variables, 195–197, 457
download site, 536
Foundation framework and, 307, 311–313
LinuxSTEP, 458
plists
ASCII format, 427
old-style format, 427
traditional format, 427
XML-style format, 429
definition of, 295–296
labels and, 295
grandchild classes, 149
GUI (graphical user interface), 3
hash tables, NSHashTable.h header file, 517
header files, 457
headers, precompiled, 315
hexadecimals, floating constants, 49
HSF files, NSHFSFileTypes.h header file, 517
HSUserDefaults.h header file, 520
I/O, NSFileHandle.h header file, 517
id data type, 53, 180–183, 457
dynamic binding and, 180–181
static typing and, 182–183
id object type
data value, 181
declaration, 501
id type, 301
identical objects, 354
identifiers, 462
directives, 462
enumeration identifier, 201–204
keywords, 462
predefined, 463–464
universal character names, 462
#if preprocessor statement, 240–241, 509–510
= (equal sign) and, 102
if-else statement and, 101
nested, 105–106
satisfied conditions, 121
if-else statement, 100–102
if statement and, 101
#ifndef statement, 238–240, 510
Imaginary data type, 69
immutable arrays, 335
immutable dictionaries, 361
immutable objects, 323–328, 457
immutable string, 418
implementation dependency, 48
implementation files
AddressBook class, 529–531
AddressCard class, 526–528
Fraction class, 522–525
Fraction.m, 128
@implementation section, 30, 35–36, 457
class definition, 496–497
#import statement, 235–238, 511
Apple and, 236
GNU and, 236
preprocessor and, 235–238
include file directory, Unix systems and, 237
include files, 238
float.h, 238
limits.h, 238
string.h, 238
#include statement, 235–238, 511
preprocessor and, 235–238
index number, 246
indirection, pointers and, 272
indirection operato r
* (operator), 273
pointers, memory address and, 292
informal protocols, 22–223, 457 . See also abstract protocols
extending classes, 152–164
instance variables and, 171–173
instance variables, 194
methods, adding to classes, 152–164
NSObject.h header file, 518
init method, 37
initialization
array elements, 248–249
character array, pointers and, 286
classes, 191–192
initialize method, 193
methods, 192
instance variables, 192
methods, 192
Foundation framework and, 192
structures, 266–267
two-dimensional arrays, 251–252
unions, 293
initialize method, 193
initializers, designated initializer, 192
initVar method, 148
input, NSRunLoop.h header file, 519
insertString:atIndex: method, 331
instance variables, 31–33, 458, 491
access, 42–45
categories and, 216
declarations, 495
extending classes through inheritance, 171–173
in structures, 300–301
inherited, 194
initialization, 192
reference counting and, 405–411
scope
controlling, 193–194
directives, 194
brackets, 26
methods, 26–27
int data type, 48
integer arithmetic, 56–58
conversions, 59–61
modulus operator, 58–59
type cast operator, 61–62
integer instance variables
denominator, 97
numerator, 97
integers, 464–465
conversions, 59–61
Interface Builder, 458
interface files, 127
AddressBook class, 526
AddressCard class, 525–526
compilers and, 128
extending, 144–145
Fraction class, 521–522
@interface section, 30–31, 458
class declarations, 127
class definition, 495
internationalization, 458
intPtr variable, 273–274
isa, 458
isa member, 300
justification, 80
keyed archives, 441–445
keyEnumerator method, 362
keys, 441–443
dictionaries, 360
keywords, 462
enum, 201–204
restrict, 477
self, 138–139
static, local variables, 137–138
super, 460
overriding, 169–171
volatile, 477
labels
definition of, 295
goto statement and, 295
language constructs
else if statement, 107–110, 113–115
if statement, 95–99
if-else statement, 100–102
statements
else if statement, 107–110, 113–115
if statement, 95–99
if-else statement, 100–102
leaking memory, 142
left shift operator, 67
#line directive, 511
linear arrays, 250
links, 458
linking files, 373
download site, 536
Foundation framework and, 307
local files, quotes, 129
local structure definition, 265
auto keyword, 199–200
functions and, 253–255
methods, arguments, 136
register keyword, 200
static, 254
static keyword, 137–138
values, 136
localization, 458
localized applications, 320
locking
NSDistributeLock.h header file, 517
NSLock.h header file, 518
logical AND operator (&&), 102–103
logical negation operator, 122
logical operators, 482
logical OR operator (||), 102–103
long long qualifier, 51–53
long qualifier, 51–53
lookup method, 350–353
lookup name in address book, 350–353
loop conditions, 75
loop variable, 120
loops
break statement, 91
continue statement, 92
do loops, 90–91
for loops, 74–85
execution order, 77
nested, 82–84
terminal input, 80–82
variants, 84–85
while loops, 85–89
lowercaseString method, 326
lvalues, expressions, 477
Mac OSX development environment, Cocoa, 1
machine dependency, 48
macros, 232–233
# operator and, 234
## operator and, 235
#define statments and, 232–233
Macintosh
classes, NSPropertyListSerialization class, 427
compiling an d
Project Builder, 10–15
Terminal window, 8–10
Foundation framework documentation, 308
OSX system
Cocoa, 456
Interface Builder, 458
Project Builder, 459
plists
old-style format, 429
traditional format, 429
XML format, 427
programs, Property List Editor program, 430
main function, 298
argc argument and, 298
argv argument and, 298
managing files. See file managemen t
managing memory . See memory management
mantissa, floating-point values, 49
map tables, NSMapTable.h header file, 518
matrixes, 250
elements, 250
two-dimensional arrays and, 250
memor y
addresses
indirection operator, 292
allocating, 156–157
autorelease pool, 399–400
cells, 291
leaking, 142
pool, autorelease pool, 317–320
releasing, 333–335
uses, 291
zones, NSZone.h header file, 520
memory management, 399
message expressions, 458, 501–502
as function calls, 301
message forwarding, 189
delegate, 189
NSInvocation.h header file, 517
Object class and, 189
class message, 185
message expressions, 458
NSPort.h header file, 518
NSProtocolChecker.h header file, 519
methods, 458
adding to classes, 152–164
arguments, 34
local variables, 136
multiple, 130–135
no name, 133
arrays, passing, 258–259
arrayWithCapacity:, 337
arrayWithObjects:, 337
as functions, 301
categories, defining, 213
choosing correct, 151
accessing variables, 197
allocF class method, 197–199
count class method, 197–199
setting variables, 197
compare, 319
conformTo method, protocols and, 221
convertToNum, 97–99
custom archiving, 444–448
decoding methods, writing, 433–438
definition, 35
class definition, 497–498
protocols and, 220
deleteCharacterslnRange:, 332
designated initializer, 456
doesNotRecognize method, 186
encoding methods, writing, 433–438
free, overriding, 169–171
getter methods, 424–425
getters, 44
init, 37
initialization methods, 192
initVar, 148
insertString:atIndex:, 331
instances, 26–27
keyed archiving, 441–445
keyEnumerator, 362
lookup, 350–353
lowercaseString, 326
multidimensional array element, passing, 259–260
mutableCopy method, 416–420
NSArray, 359–360
NSDictionary methods, 364–365
NSFileHandle class, 373
NSFileHandle object, 392–393
NSFileManager
directories, 380–381
files, 374
NSMethodSignature.h header file, 518
NSMutableArray, 360
NSMutableDictionary methods, 365
NSMutableSet, 369
NSMutableString methods, 335
NSPathUtilities.h, 385
NSProcessInfo, 389
NSSet, 369
NSString method, 333–334
objects
allocating, 139–145
returning, 139–145
path utilities, 387–388
perform method, 186
pointers, returning as result, 278–279
poseAs method, 217–219
print, 366–368
propertyList method, 431
rangeOfString:, 332
release, 343–350
removeCard, 353–356
removeObject:, 354
root object, 513–514
selected, 166
setOrigin, 161
setString:, 332
setter methods, 424–425
setters, 44
setWithObject:, 368
substringToIndex, 327
substringWithRange, 328
uppercaseString, 326
writeToFile method
NSArray object, 427
NSData object, 427
NSDictionary object, 427
NSString object, 427
MinGW system
compiler, 16
download site, 536
Foundation framework and, 307, 311–313
modules, 193
modulus operator, 58–59
% (percent), 100
multibyte characters, character string constants, 467
multidimensional arrays, 250–252, 471–472
elements
passing functions to, 259–260
passing methods to, 259–260
mutable arrays, 335
mutable dictionaries, 361
mutableCopy method, 416–420
name definitions, 229–233
named pairs, object/category, 217
names
address book
deleting, 353–356
lookup, 350–353
files, 9
naming conventions, 31–33
case sensitivity, 32
reserved names, 32
negation operator, 122
nested if statement, 105–106
nested for loops, 82–84
newline character, 19
NXObject, 459
nil, 458
notifications, 458
NSNotification.h header file, 518
NSNotificationQueue.h header file, 518
NSAppleEventDescriptor.h header file, 515
NSAppleEventManager.h header file, 515
NSAppleScript.h header file, 515
NSArchiver class, 431–433
NSArchiver.h header file, 515
NSArray methods, 359–360
NSArray.h header file, 515
NSAttributedString.h header file, 516
NSAutoreleasePool.h heder file, 516
NSBundle.h header file, 516
NSByteOrder.h header file, 516
NSCalendarDate.h header file, 516
NSCharacterSet.h header file, 516
NSClassDescription.h header file, 516
NSCoder.h header file, 516
NSCoding protocol, 434
NSCompatibility.h header file, 516
NSConnection.h header file, 516
NSCopying protocol, 449
NSCountedSet class, 368
NSData class, 378–380
NSData object, 444–448
NSData.h header file, 516
NSDate.h header file, 516
NSDateFormatter.h header file, 516
NSDebug.h header file, 516
NSDecimal.h header file, 516
NSDecimalNumber.h header file, 516
NSDictionary methods, 364–365
NSDictionary.h header file, 517
NSDistantObject.h header file, 517
NSDistributedLock.h header file, 517
NSDistributedNotificationCenter.h header file, 517
NSEnumerator.h header file, 517
NSError.h header file, 517
NSException.h header file, 517
NSFileHandle class methods, 373
NSFileHandle object methods, 392–393
NSFileHandle.h header file, 517
NSFileManager, 374–384
methods
directories, 380–381
files, 374
NSFileManager.h header file, 517
NSFormatter.h header file, 517
NSGeometry.h header file, 517
NSHashTable.h header file, 517
NSHFSFileTypes.h header file, 517
NSHomeDirectory function, 387
NSHost.h header file, 517
NSHTTPCookie.h header file, 517
NSHTTPCookieStorage.h header file, 517
NSInvocation.h header file, 517
NSJavaSetup.h header file, 517
NSKeyedArchiver.h header file, 518
NSKeyValueCoding.h header file, 518
NSLock.h header file, 518
NSLog function, 321–323
NSMapTable.h header file, 518
NSMethodSignature.h header file, 518
NSMutableArray methods, 360
NSMutableDictionary methods, 365
NSMutableSet methods, 369
NSMutableString class, 323
NSMutableString methods, 335
NSNetServices.h header file, 518
NSNotification.h header file, 518
NSNotificationQueue.h header file, 518
NSNull.h header file, 518
NSNumber objects, 318
NSNumberFormatter.h header file, 518
NSObjCRuntime.h header file, 518
NSObject.h header file, 518
NSObjectScripting.h header file, 518
NSPathUtilities.h header file, 384–392, 518
NSPort.h header file, 518
NSPortCoder.h header file, 518
NSPortMessage.h header file, 519
NSPortNameServer.h header file, 519
NSProcessInfo class, 388–392
NSProcessInfo.h header file, 519
NSPropertyList.h header file, 519
NSProtocolChecker.h header file, 519
NSProxy.h header file, 519
NSRange.h header file, 519
NSRunLoop.h header file, 519
NSScanner.h header file, 519
NSScript header files, 519
NSSerialization.h header file, 519
NSSet methods, 369
NSSet.h header file, 519
NSSpellServer.h header file, 519
NSString methods, 333–334
NSString.h header file, 520
NSTask.h header file, 520
NSTemporaryDirectory function, 386
NSThread.h header file, 520
NSTimer.h header file, 520
NSTimeZone.h header file, 520
NSUnarchiver class, 432
NSUndoManager.h header file, 520
NSURL header files, 520
NSURL.h header file, 520
NSURLHandle.h header file, 520
NSUtilities.h header file, 520
NSValue.h header file, 520
NSZone.h header file, 520
null objects, NSNull.h header file, 518
null pointer, 459
number objects, 315–320
numbers
Fibonacci numbers, 247–248
floating point, 21
index number, as reference, 246
NSNumberFormatter.h header file, 518
NSValue.h header file, 520
real numbers, 21
subscript, as reference, 246
triangular, 73
truncated, 60
numerator integer instance variable, 97
NXObject, 459
Object class, 186
message forwarding, 189
object variables, as pointer variables, 301
object-orientation, 25
object-oriented programming, 272, 459
object/category named pairs, 217
Objective-C
history of, 1
resources for further information
books, 533–534
Web sites, 534
array objects, 335–360
class objects, 456
class ownership, 161–164
collections, 456
composite objects, 223–224
constant character string objects, 467
copying, 415–418
getter methods and, 424–425
setter methods and, 424–425
with archiver, 448–449
deep copying, 418–420
defining, 500–501
id object, 501
delegates, 456
dictionary, 360–365
NSDictionary.h header file, 517
distributed
NSConnection.h header file, 516
NSDistantObject.h header file, 517
NSDistributeNotificationCenter.h header file, 517
NSPortCoder.h header file, 518
NSPortMessage.h header file, 519
Distributed Objects, 456
factory, 457
id object, declaration, 501
identical, 354
memory release, 333–335
methods
allocating, 139–145
returning, 139–145
mutable copying, 416–418
nil object, 458
NSArray, writeToFile method, 427
NSData, 445
custom archiving, 444–448
writeToFile method, 427
NSDictionary, writeToFile method, 427
NSString, writeToFile method, 427
number objects, 315–320
numbers as, NSValue.h header, 520
referencing, 400–411
releasing, 343–350
set, 365–369
NSSet.h header file, 519
shallow copying, 418–420
Square object, 185
string, 320–335
NSString.h header file, 520
types, id object type, 457
octal notation, int data type, 48
one-dimensional arrays, 250
ones complement operator, 67
ONESTEP, 1
opening files, 373
OPENSTEP, 459
operations
increment operation
post-increment, 287
pre-increment, 287
on pointers, 289–291
operators, 478–480
& operator, pointers and, 273
&& (logical AND operator), 102–103
|| (logical OR operator), 102–103
address operator, pointers and, 273
binary, 54
bit operators, 65–69
precedence, 54
type cast operator, 61–62
arrays and, 485
bit, 270
bitwise, 482–483
blank spaces and, 105
as ternary operator, 123
else if clause and, 124
parentheses, 124
dot, 261
indirection (*), 273
logical AND (&&), 102–103
logical negation, 122
logical, 482
logical OR (||), 102–103
modulus, 58–59
% (percent), 100
pointers and, 486
pointers to arrays, 486–487
pointers to structures, 487
post-increment, 287–288
pre-increment, 287–288
reading into character variable operator, 113
sizeof operator, 296–297, 443, 484
structures and, 485–486
ternary operator, 123
type cast, 484
unary minus operator, 122
unary operator, pointers and, 273
OR operator ( | | ), 102–103
origin values, storing as separate, 156
overriding
keywords, super, 169–171
methods, 164–171
categories, subclassing and, 216
parameters, as register variables, 200
parentheses around condition operators, 124
parsing, NSScanner.h header file, 519
pathnames, 374
absolute, 374
NSPathUtilies.h header file, 384–392, 518
relative, 374
utilities
functions, 388
methods, 387–388
percent (%) character, 22
perform method, 186
plists (property lists), 427–430
archiving with, 427–430
creating from dictionary, 429
GNUstep systems, format, 427–429
Macs
binary-serialized plists, 427
Property List Editor program, 430
NSPropertyList.h header file, 519
propertyList method, 431
reading from URL, 431
writing to URL, 431
pointers, 37, 272–276, 459, 475–476
& operator and, 273
address operator and, 273
arrays and, 280–283
character arrays and, 286
character strings and, 284–285
charPtr variable, 275–276
constant character strings and, 285–286
decrement operator (—), 282, 286-288
definition of, 272
function pointers, 494
dispatch tables, 291
passing to, 278–279
increment operator (++), 282, 286–288
indirection and, 272
operator, memory address and, 292
intPtr variable, 273–274
memory addresses and, 291–292
methods, passing to, 278–279
null pointer, 459
operations, 289–291
operators and, 486
pointers to arrays, 486–487
pointers to structures, 487
as an argument, 278–279
to character string, 284–285
to constant character string, 285–286
to function, 290–291
post-increment operator, 287–288
pre-increment operator, 287–288
structures and, 276–277
types, id type, 301
unary operator and, 273
class addition and, 179
class development and, 179
ports, registering, 519
poseAs method, 217–219
positive integers, prime numbers and, 119
post-increment operator, 287–288
pound sign (#), preprocessor and, 227
#pragma directive, 512
pre-increment operation, 287–288
precedence, arithmetic operators, 54
precompiled headers, 315
predefined directives, 512
predefined identifiers, 463–464
conditional compilation, 238–240
definition of, 227
directives, 507
#error, 509
#if, 509–510
#ifdef, 510
#ifndef, 510
#line, 511
#pragma, 512
#undef, 512
predefined, 512
preprocessor definition, 230
trigraph sequences, 507
prime numbers, 119
primes array, allocation and, 339
print method, 366–368
printf statement, 28
@private directive, 194
procedural programming language, 2, 459
program development, framework, 2
program section, 36–45
program statements, if statement and, 95
programming errors
unkown operator entry, 113–115
Programming is fun source, 7
Project Builder, 459
Build menu, 14
compiling on Macs, 10–15
Foundation framework (Mac), 310–311
Property List Editor program, 430
property lists. See plists
@protected directive, 194
abstract, 222
adopting, 219–220
category adoption of, 222
conforming to, 219
definition, 219
formal protocols, 457
Foundation framework and, 219
methods
conformTo method, 221
defining, 220
NSCoding protocol, 434
NSCopying protocol, 449
@protocol directive, 221
@protocol directive, 221
prototype declaration
definition of, 257
functions and, 257
@public directive, 194
qsort function, 291
qualifiers, data types, 51–53
quotes, local files, 129
rangeOfString: method, 332
ranges, 326
NSRange.h header file, 519
reading for further information
C programming language, 534
Cocoa, 535
Objective-C, 533–534
real numbers, 21
Rectangle class, 187–188
Redo operations, NSUndoManager.h header file, 520
reference counting, 400–411
instance variables and, 405–411
strings and, 403–405
reference numbers
index number, 246
subscript, 246
register keyword, 200
register variables, 200
parameters as, 200
relative pathnames, 374
release method, address book project and, 343–350
releasing
memory
autorelease pool, 399–400
objects, 333–335
objects, 343–350
removeCard method, 353–356
removeObject: method, 354
reserved names/words, 32
resources
books
C programming language, 534
Cocoa, 535
Objective-C, 533–534
exercise answers, 533
Foundation framework, Mac, 308
Web sites
C programming language, 534
Cocoa, 535
Foundation framework, 535
Objective-C, 534
restrict keyword, 477
results, returning, 255–256
retrieval methods, NSNumber object, 318
return statement, 505
return type declaration, functions and, 256–258
right justification, 80
right shift operator, 67–69
root, 147
root directory, 374
root object, 459
Foundation framework, 313
methods, 513–514
routines
calls, 19
getter routine, 424–425
setter routine, 424–425
runtime, 459
runtime checking, 182
satisfied conditions, if statements, 121
scientific notation, 49
scope, 489
instance variables, directives, 194
variables, 193
scripting, NSObjectScripting.h header file, 518
@selector directive, 186
semicolon, 19
serialization, NSSerializer.h header file, 519
services, NSNetServices.h header file, 518
NSSet.h header file, 519
setOrigin method, 161
setString: method, 332
setter methods, 424–425
setter routine, 424–425
setters, 44
setWithObject: method, 368
short qualifier, 51–53
sign extension, 207–208
sign function, 107
signed char variable, 208
signed qualifier, 51–53
signed quantities, characters as, 207
single-dimensional arrays, 470
sizeof operators, 296–297, 484
slashes (/ / ), comments, 18
sorting arrays, address book project, 356–360
special type BOOL, 122
spell checker, NSSpellServer.h header file, 519
Square class, 187–188
as subclass, 154
Square object, 185
state, 26
statement block, 460
blocks, 79
compound, 502–506
continue statement, 92
debugging statments, 240
#define statement, 227–229
backslash character, 231
arguments, 231
constant values and, 229
defined names, 229–233
macros, 232–233
placement of, 228
syntax, 228
do loops, 90–91
#elif preprocessor statement, 240–241
#else, 238–240
else if statement, 107–110, 113–115
n-valued logic decision, 107
#endif statment, 238–240
for loops, 74–85
goto statement, 295–296
#if preprocessor statement, 240–241
if statement, 95–99
nested, 105–106
program statements and, 95
if-else statement, 100–102
#ifdef statement, 238–240
#ifndef statement, 238–240
#import statement, 235–238
Apple and, 236
GNU and, 236
#include statement, 235–238
null statement, 296
printf, 28
program statement, if statement and, 95
statement block, 460
switch statement, 116–119
definition procedure, 205
Foundation framework and, 205
#undef statement, 242
while loops, 85–89
static keyword, local variables, 137–138
static local variables, 254
storage buffer, 378
storage class, 489
functions, 490
variables, 490
string objects, 320–335
constant character string object, 321
NSString.h header file, 520
strings
attributes, NSAttributedString.h header file, 516
character string constants, 467
concatenation, 467
multibyte characters, 467
objects, 467
wide, 467
character strings, 250, 320, 456
constant character string, 456
format strings, 23
immutable string, 418
ranges, 326
reference counting and, 403–405
structure variables, 261
structures, 260–270, 460, 472–474
arrays of, 267
bit fields, 270–271
classes and, 265
defining, 267
variables and, 269–270
global structure definition, 265
initializating, 266–267
instance variables, storage in, 300–301
local structure definition, 265
members, isa member, 300
operators and, 485–486
structure definitions, 265
structures within, 267–269
syntax of, 261
alternative to, 223
categories and, 216
concrete subclass, 456
creating, 154
designated initializer and, 192
subscripts, 246
substringTolndex method, 327
substringWithRange method, 328
super keywords, 460
overriding, 169–171
superclass, 460
switch statement, 116–119, 505–506
break statement and, 116
file statement, translation into, 117
syntax, structures, 261
system informatio n
NSHost.h header file, 517
NSProcesslnfo.h header file, 519
tables, dispatch tables, 291
Terminal (Macintosh)
compiling, 8–10
Foundation framework and, 311
terminal input, for loops, 80–82
terminating null character, 250
character array and, 250
ternary operator, 123
conditional operator as, 123
threading, NSThread.h header file, 520
tilde (~), home directory, 374
time, NSCalendarDate.h header file, 516
time zones, NSTimeZone.h header file, 520
timers, NSTimer.h header file, 520
tools
gdb debugging tool, 457
Interface Builder, 458
Xcode, 460
triangular numbers, 73
trigraphs, 507
truncation, 60
two-dimensional arrays, 250–251
elements, 250
matrixes and, 250
type cast operators, 61–62, 484
type modifiers, protocol definitions, 500
typedef statement, 191, 204–205, 476
definition procedure, 205
Foundation framework and, 205
types
BOOL (special type), 122
dynamic types, methods for working with, 185
typing
static typing, 182–183
unarchiving objects, 434
unary operator, pointers and, 273
Undo operations, NSUndoManager.h header file, 520
unichar characters, 320
Unicode character, 460
arrays, defining with, 293
declaring, 292
defining, 293
initialization, 293
units
bit fields, 271
definition of, 271
universal character names, 462
Unix systems, include file directory, 237
unsigned character variable, 208
unsigned qualifier, 51–53
uppercaseString method, 326
URLs
header files, 520
plists
reading from, 431
writing to, 431
user settings, HSUserDefaults.h header file, 520
usernames, NSPathUtilies.h header file, 518
usual arithmetic conversions, 488–489
values
built-in
NO, 122
YES, 122
returning, 255–256
variables
displaying, 21–23
local variables, 136
variable-length arrays, 471
variables
automatic variable, 455
Boolean variables, 119–123
character variables, unsigned, 208
charPtr variable, 275–276
const keyword, 200
dataValue variable, 181
external global variable, 195
external variable, 195–197
extern keyword, 195–198
static keyword, 197–199
global variables, 195–197, 457
instance variables, 31–33, 458, 491
access, 42–45
categories and, 216
declarations, 495
extending classes and, 171–173
inherited, 194
initialization, 192
isa variable, 458
reference counting and, 405–411
scope control, 193–194
integer instance, denominator, 97
integer instance variable numerator, 97
intPtr, 273–274
keywords
auto, 199–200
const, 200
extern, 195–198
register, 200
static, 197–199
volatile, 200–201
auto keyword, 199–200
functions and, 253–255
method arguments, 136
register keyword, 200
values, 136
loop variable, 120
object variable as pointer variable, 301
pointer variable, restrict modifier, 200
scope, 193
self variable, 460
signed char variable, 208
static variable, 460
storage class, 490
structure definition and, 269–270
structure variables, 261
values, displaying, 21–23
volatile keyword, 200–201
variants, for loops, 84–85
volatile keyword, 477
volatile variable, 200–201
Web sites
C programming language, 534
Cocoa, 535
downloads
CygWin, 536
gcc, 536
GNUstep, 536
LinuxSTEP, 536
MinGW, 536
exercise answers, 533
Foundation framework, 535
Objective-C, 534
wide character constants, 466
wide character string constants, 467
Windows, compiling and, 16–17
XML (Extensible Markup Language), 460
zone, 460
zone argument, 422
3.145.55.198