Skip to Content
Our misssion: to make the life easier for the researcher of free ebooks.

The Objective-C 2.0 Programming Language

The Objective-C language is a simple computer language designed to enable sophisticated object-oriented programming. Objective-C is defined as a small but powerful set of extensions to the standard ANSI C language. Its additions to C are mostly based on Smalltalk, one of the first object-oriented programming languages. Objective-C is designed to give C full object-oriented programming capabilities, and to do so in a simple and straightforward way.

Most object-oriented development environments consist of several parts:

  • An object-oriented programming language
  • A library of objects
  • A suite of development tools
  • A runtime environment

This document is about the first component of the development environment—the programming language. It fully describes the Objective-C language, and provides a foundation for learning about the second component, the Mac OS X Objective-C application frameworks—collectively known as Cocoa. You can start to learn more about Cocoa by reading Getting Started with Cocoa. The two main development tools you use are Xcode and Interface Builder, described in Xcode Workspace Guide and Interface Builder respectively. The runtime environment is described in a separate document, Objective-C 2.0 Runtime Programming Guide.

Contents
Introduction Introduction to The Objective-C 2.0 Programming Language

    Who Should Read This Document
    Organization of This Document
    Conventions
    See Also
      Runtime
      Memory Management

Chapter 1 Objects, Classes, and Messaging

    Runtime
    Objects
      Object Basics
      id
      Dynamic Typing
      Memory Management

    Object Messaging

      Message Syntax
      Sending Messages to nil
      The Receiver’s Instance Variables
      Polymorphism
      Dynamic Binding
      Dynamic Method Resolution
      Dot Syntax

    Classes

      Inheritance
      Class Types
      Class Objects
      Class Names in Source Code
      Testing Class Equality

Chapter 2 Defining a Class

    Source Files
    Class Interface
      Importing the Interface
      Referring to Other Classes
      The Role of the Interface

    Class Implementation

      Referring to Instance Variables
      The Scope of Instance Variables

    Messages to self and super

      An Example
      Using super
      Redefining self

Chapter 3 Allocating and Initializing Objects

    Allocating and Initializing Objects
    The Returned Object
    Implementing an Initializer
      Constraints and Conventions
      Handling Initialization Failure
      Coordinating Classes

    The Designated Initializer
    Combining Allocation and Initialization

Chapter 4 Declared Properties

    Overview
    Property Declaration and Implementation
      Property Declaration
      Property Declaration Attributes
      Property Implementation Directives

    Using Properties

      Supported Types
      Property Re-declaration
      Copy
      dealloc
      Core Foundation
      Example

    Subclassing with Properties
    Performance and Threading
    Runtime Difference

Chapter 5 Categories and Extensions

    Adding Methods to Classes
    How you Use Categories
    Categories of the Root Class
    Extensions

Chapter 6 Protocols

    Declaring Interfaces for Others to Implement
    Methods for Others to Implement
    Declaring Interfaces for Anonymous Objects
    Non-Hierarchical Similarities
    Formal Protocols
      Declaring a Protocol
      Optional Protocol Methods

    Informal Protocols
    Protocol Objects
    Adopting a Protocol
    Conforming to a Protocol
    Type Checking
    Protocols Within Protocols
    Referring to Other Protocols

Chapter 7

    Fast Enumeration
    The for…in Feature
    Adopting Fast Enumeration
    Using Fast Enumeration

Chapter 8 Enabling Static Behavior

    Default Dynamic Behavior
    Static Typing
    Type Checking
    Return and Argument Types
    Static Typing to an Inherited Class

Chapter 9 Selectors

    Methods and Selectors
      SEL and @selector
      Methods and Selectors
      Method Return and Argument Types

    Varying the Message at Runtime
    The Target-Action Design Pattern
    Avoiding Messaging Errors

Chapter 10 Exception Handling

    Enabling Exception-Handling
    Exception Handling
    Catching Different Types of Exception
    Throwing Exceptions

Chapter 11 Threading

    Synchronizing Thread Execution

Chapter 12 Remote Messaging
Distributed Objects
Language Support

    Synchronous and Asynchronous Messages
    Pointer Arguments
    Proxies and Copies

Chapter 13 Using C++ With Objective-C

    Mixing Objective-C and C++ Language Features
    C++ Lexical Ambiguities and Conflicts
    Limitations
    Appendix A
      Language Summary
      Messages
      Defined Types
      Preprocessor Directives
      Compiler Directives
      Classes
      Categories
      Formal Protocols
      Method Declarations
      Method Implementations
      Deprecation Syntax
      Naming Conventions

Glossary
Document Revision History
Index

Download
The Objective-C 2.0 Programming Language