Table of Contents
1. Introduction
I. The Objective-C Language
2. Programming in Objective-C
Compiling and Running Programs on the Mac
Compiling Programs in a Terminal Window
Compiling and Running Programs Using Project Builder
Compiling and Running Programs under Windows
Line-by-Line Explanation of Your First Program
Comments
Displaying the Values of Variables
Exercises
3. Classes, Objects, and Methods
What Is an Object, Anyway?
Instances and Methods
An Objective-C Class for Working with Fractions
The @interface
Section
Choosing Names
Instance Variables
Class and Instance Methods
The @implementation
Section
The Program Section
Accessing Instance Variables and Data Encapsulation
Exercises
4. Data Types and Expressions
Data Types and Constants
Type int
Type float
Type double
Type char
Qualifiers: long, long long, short, unsigned, and signed
Type id
Arithmetic Expressions
Integer Arithmetic and the Unary Minus Operator
Assignment Operators
A Calculator Class
Bit Operators
The Bitwise AND Operator
The Bitwise Inclusive-OR Operator
The Bitwise Exclusive-OR Operator
The Ones Complement Operator
The Left Shift Operator
The Right Shift Operator
Types: _Bool
, _Complex
, and _Imaginary
Exercises
5. Program Looping
The for
Statement
Terminal Input
Nested for Loops
for Loop Variants
The while
Statement
The do
Statement
The break
Statement
The continue
Statement
Exercises
6. Making Decisions
The if
Statement
The if-else Construct
Compound Relational Tests
Nested if Statements
The else if Construct
The switch
Statement
Boolean Variables
The Conditional Operator
Exercises
7. More on Classes
Separate Interface and Implementation Files
Multiple Arguments to Methods
Methods Without Argument Names
Operations on Fractions
Local Variables
Method Arguments
The static Keyword
The self
Keyword
Allocating and Returning Objects from Methods
Extending Class Definitions and the Interface File
Exercises
8. Inheritance
It All Begins at the Root
Finding the Right Method
Extension Through Inheritance—Adding New Methods
A Point Class and Memory Allocation
The @class Directive
Classes Owning Their Objects
Overriding Methods
Which Method Is Selected?
Overriding the free Method and the Keyword super
Extension Through Inheritance—Adding New Instance Variables
Abstract Classes
Exercises
9. Polymorphism, Dynamic Typing, and Dynamic Binding
Polymorphism: Same Name, Different Class
Dynamic Binding and the id
Type
Compile Time Versus Runtime Checking
The id
Data Type and Static Typing
Argument and Return Types with Dynamic Typing
Asking Questions About Classes
Message Forwarding
Exercises
10. More on Variables and Data Types
Initializing Classes
Initializing Classes: The initialize Method
Scope Revisited
Directives for Controlling Instance Variable Scope
External Variables: extern and static
Static Versus Extern Variables
Storage Class Specifiers
auto
register
const
volatile
Enumerated Data Types
The typedef
Statement
Data Type Conversions
Sign Extension
Exercises
11. Categories, Posing, and Protocols
Categories
Some Notes About Categories
Posing
Protocols
Informal Protocols
Composite Objects
Exercises
12. The Preprocessor
The #define
Statement
More Advanced Types of Definitions
The # Operator
The ## Operator
The #import
and #include
Statements
Conditional Compilation
The #ifdef, #endif, #else, and #ifndef Statements
The #if and #elif Preprocessor Statements
The #undef Statement
Exercises
13. Underlying C Language Features
Arrays
Initializing Array Elements
Character Arrays
Multidimensional Arrays
Functions
Arguments and Local Variables
Returning Function Results
Functions, Methods, and Arrays
Structures
Initializing Structures
Arrays of Structures
Structures Within Structures
Additional Details About Structures
Don't Forget About Object-Oriented Programming!
Pointers
Pointers and Structures
Pointers, Methods, and Functions
Pointers and Arrays
Operations on Pointers
Pointers and Memory Addresses
Unions
They're Not Objects!
Miscellaneous Language Features
Compound Literals
The goto Statement
The null Statement
The Comma Operator
The sizeof Operator
Command-Line Arguments
How Things Work
Exercises
II. The Foundation Framework
14. Introduction to the Foundation Framework
Foundation Programs on the Mac
Foundation Documentation
Compiling Foundation Programs Using Project Builder
Compiling Foundation Programs Using Terminal
Foundation Programs Under GNUStep
The Root Object: NSObject
Exercises
15. Numbers, Strings, and Collections
Number Objects
A Quick Look at the Autorelease Pool
String Objects
The NSLog Function
Mutable Versus Immutable Objects
Mutable Strings
Where Are All Those Objects Going?
Array Objects
Making an Address Book
Sorting Arrays
Dictionary Objects
Enumerating a Dictionary
Set Objects
Exercises
16. Working with Files
Managing Files and Directories: NSFileManager
Working with the NSData Class
Working with Directories
Enumerating the Contents of a Directory
Working with Paths: NSPathUtilities.h
A Program to Copy Files and the NSProcessInfo Class
Basic File Operations: NSFileHandle
Exercises
17. Memory Management
The Autorelease Pool
Multiple Autorelease Pools
Reference Counting
Reference Counting and Strings
Reference Counting and Instance Variables
Back to the Autorelease Pool
Summary of Memory Management Rules
Exercises
18. Copying Objects
The copy
and mutableCopy
Methods
Shallow Versus Deep Copying
Implementing the <NSCopying>
Protocol
Copying Fractions
Copying Objects in Setter and Getter Methods
Exercises
19. Archiving
Archiving with Property Lists
Property Lists and URLs
Archiving with NSArchiver
Writing Encoding and Decoding Methods
Archiving Basic Objective-C Data Types
Keyed Archives
Using NSData
to Create Custom Archives
Using the Archiver to Copy Objects
Exercises
Afterword
III. Appendixes
A. Glossary
B. Objective-C Language Summary
Digraphs and Identifiers
Digraph Characters
Identifiers
Comments
Constants
Integer Constants
Floating-point Constants
Character Constants
Character String Constants
Enumeration Constants
Data Types and Declarations
Declarations
Basic Data Types
Derived Data Types
Enumerated Data Types
typedef
Type Modifiers: const, volatile, and restrict
Expressions
Summary of Objective-C Operators
Constant Expressions
Arithmetic Operators
Logical Operators
Relational Operators
Bitwise Operators
Increment and Decrement Operators
Assignment Operators
Conditional Operator
Type Cast Operator
sizeof Operator
Comma Operator
Basic Operations with Arrays
Basic Operations with Structures
Basic Operations with Pointers
Compound Literals
Conversion of Basic Data Types
Storage Classes and Scope
Functions
Variables
Instance Variables
Functions
Function Definition
Function Call
Function Pointers
Classes
Class Definition
Category Definition
Protocol Definition
Object Declaration
Message Expressions
Statements
Compound Statements
The break Statement
The continue Statement
The do Statement
The for Statement
The goto Statement
The if Statement
The null Statement
The return Statement
The switch Statement
The while Statement
The Preprocessor
Trigraph Sequences
Preprocessor Directives
Predefined Identifiers
Root Object Methods and Categories
C. Foundation Framework Headers
D. Fraction and Address Book Examples
The Fraction
Class
Fraction Class Interface File
Fraction Class Implementation File
The AddressBook
and AddressCard
Classes
AddressCard Interface File
AddressBook Interface File
AddressCard Implementation File
AddressBook Implementation File
E. Resources
Answers to Exercises, Errata, and so on
The Objective-C Language
Books
Web Sites
The C Programming Language
Books
Web Sites
The Foundation Framework
Web Sites
Cocoa
Books
Web Sites
Compilers and Development Environments
gcc
MinGW
CygWin
GNUStep
LinuxSTEP
Index