You are previewing Programming in Objective-C, Fifth Edition.
O'Reilly logo
Programming in Objective-C, Fifth Edition

Book Description

Programming in Objective-C, Fifth Edition
Updated for OS X Mountain Lion, iOS 6, and Xcode 4.5

Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming for Apple's iOS and OS X platforms.

The book makes no assumptions about prior experience with object-oriented programming languages or with the C language (which Objective-C is based upon). Because of this, both beginners and experienced programmers alike can use this book to quickly and effectively learn the fundamentals of Objective-C. Readers can also learn the concepts of object-oriented programming without having to first learn all of the intricacies of the underlying C programming language.

This unique approach to learning, combined with many small program examples and exercises at the end of each chapter, makes Programming in Objective-C ideally suited for either classroom use or self-study.

This edition has been fully updated to incorporate new features in Objective-C programming introduced with Xcode 4.4 (OS X Mountain Lion) and Xcode 4.5 (iOS 6.)

“The best book on any programming language that I’ve ever read. If you want to learn Objective-C, buy it.”–Calvin Wolcott

“An excellent resource for a new programmer who wants to learn Objective-C as their first programming language–a woefully underserved market.”–Pat Hughes

Contents at a Glance

1 Introduction

Part I The Objective-C Language
2 Programming in Objective-C
3 Classes, Objects, and Methods
4 Data Types and Expressions
5 Program Looping
6 Making Decisions
7 More on Classes
8 Inheritance
9 Polymorphism, Dynamic Typing, and Dynamic Binding
10 More on Variables and Data Types
11 Categories and Protocols
12 The Preprocessor
13 Underlying C Language Features

Part II The Foundation Framework
14 Introduction to the Foundation Framework
15 Numbers, Strings, and Collections
16 Working with Files
17 Memory Management and Automatic Reference Counting (ARC)
18 Copying Objects
19 Archiving

Part III Cocoa, Cocoa Touch, and the iOS SDK
20 Introduction to Cocoa and Cocoa Touch
21 Writing iOS Applications

Appendixes
A Glossary
B Address Book Program Source Code

Table of Contents

  1. Title Page
  2. Copyright Page
  3. Dedication Page
  4. Contents at a Glance
  5. Table of Contents
  6. Developer’s Library
  7. About the Author
  8. About the Technical Reviewers
  9. We Want to Hear from You!
  10. Reader Services
  11. 1. Introduction
    1. What You Will Learn from This Book
    2. How This Book Is Organized
    3. Support
    4. Acknowledgments
    5. Preface to the Fifth Edition
  12. Part I: The Objective-C Language
    1. 2. Programming in Objective-C
      1. Compiling and Running Programs
      2. Explanation of Your First Program
      3. Displaying the Values of Variables
      4. Summary
      5. Exercises
    2. 3. Classes, Objects, and Methods
      1. What Is an Object, Anyway?
      2. Instances and Methods
      3. An Objective-C Class for Working with Fractions
      4. The @interface Section
      5. The @implementation Section
      6. The program Section
      7. Accessing Instance Variables and Data Encapsulation
      8. Summary
      9. Exercises
    3. 4. Data Types and Expressions
      1. Data Types and Constants
      2. Arithmetic Expressions
      3. Assignment Operators
      4. A Calculator Class
      5. Exercises
    4. 5. Program Looping
      1. The for Statement
      2. The while Statement
      3. The do Statement
      4. The break Statement
      5. The continue Statement
      6. Summary
      7. Exercises
    5. 6. Making Decisions
      1. The if Statement
      2. The switch Statement
      3. Boolean Variables
      4. The Conditional Operator
      5. Exercises
    6. 7. More on Classes
      1. Separate Interface and Implementation Files
      2. Synthesized Accessor Methods
      3. Accessing Properties Using the Dot Operator
      4. Multiple Arguments to Methods
      5. Local Variables
      6. The self Keyword
      7. Allocating and Returning Objects from Methods
      8. Exercises
    7. 8. Inheritance
      1. It All Begins at the Root
      2. Extension through Inheritance: Adding New Methods
      3. Overriding Methods
      4. Abstract Classes
      5. Exercises
    8. 9. Polymorphism, Dynamic Typing, and Dynamic Binding
      1. Polymorphism: Same Name, Different Class
      2. Dynamic Binding and the id Type
      3. Compile Time Versus Runtime Checking
      4. The id Data Type and Static Typing
      5. Asking Questions about Classes
      6. Exception Handling Using @try
      7. Exercises
    9. 10. More on Variables and Data Types
      1. Initializing Objects
      2. Scope Revisited
      3. Enumerated Data Types
      4. The typedef Statement
      5. Data Type Conversions
      6. Bit Operators
      7. Exercises
    10. 11. Categories and Protocols
      1. Categories
      2. Class Extensions
      3. Protocols and Delegation
      4. Composite Objects
      5. Exercises
    11. 12. The Preprocessor
      1. The #define Statement
      2. The #import Statement
      3. Conditional Compilation
      4. Exercises
    12. 13. Underlying C Language Features
      1. Arrays
      2. Functions
      3. Blocks
      4. Structures
      5. Pointers
      6. They’re Not Objects!
      7. Miscellaneous Language Features
      8. How Things Work
      9. Exercises
  13. Part II: The Foundation Framework
    1. 14. Introduction to the Foundation Framework
      1. Foundation Documentation
    2. 15. Numbers, Strings, and Collections
      1. Number Objects
      2. String Objects
      3. Array Objects
      4. Dictionary Objects
      5. Set Objects
      6. Exercises
    3. 16. Working with Files
      1. Managing Files and Directories: NSFileManager
      2. Working with Paths: NSPathUtilities.h
      3. Basic File Operations: NSFileHandle
      4. The NSURL Class
      5. The NSBundle Class
      6. Exercises
    4. 17. Memory Management and Automatic Reference Counting
      1. Automatic Garbage Collection
      2. Manual Reference Counting
      3. The Event Loop and Memory Allocation
      4. Summary of Manual Memory Management Rules
      5. Automatic Reference Counting
      6. Strong Variables
      7. Weak Variables
      8. @autoreleasepool Blocks
      9. Method Names and Non-ARC Compiled Code
    5. 18. Copying Objects
      1. The copy and mutableCopy Methods
      2. Shallow Versus Deep Copying
      3. Implementing the <NSCopying> Protocol
      4. Copying Objects in Setter and Getter Methods
      5. Exercises
    6. 19. Archiving
      1. Archiving with XML Property Lists
      2. Archiving with NSKeyedArchiver
      3. Writing Encoding and Decoding Methods
      4. Using NSData to Create Custom Archives
      5. Using the Archiver to Copy Objects
      6. Exercises
  14. Part III: Cocoa, Cocoa Touch, and the iOS SDK
    1. 20. Introduction to Cocoa and Cocoa Touch
      1. Framework Layers
      2. Cocoa Touch
    2. 21. Writing iOS Applications
      1. The iOS SDK
      2. Your First iPhone Application
      3. An iPhone Fraction Calculator
      4. Summary
      5. Exercises
  15. Appendixes
    1. Appendix A. Glossary
    2. Appendix B. Address Book Example Source Code
  16. Index
  17. Ad Page