Elements of the Language

Objective-C extends the C language with the following concepts and constructs:

  • Objects (instances of classes)

  • Classes

  • Inheritance and subtyping

  • Fields

  • Methods and method calls (or messages)

  • Categories

  • Protocols

  • Declarations (extended from C to include class and protocol types)

  • Predefined types, constants, and variables

  • Compiler and preprocessor directives

The following sections will describe these aspects of Objective-C.

Objects

Objects are the compound values—data and operations—at the heart of object-oriented programming. They are generalizations of simple structured types found in C and many other languages. Like C structs, objects have components—data fields—that maintain state. For example, a Book object might have fields to specify the author and publisher. In addition, objects interact through message passing, which provides an alternative to the function calls of a procedural language.

Objective-C objects have these attributes:

Class

An object type. An object whose type is MyClass is said to be an instance of MyClass.

Fields

Data members of an object. An object has its own copies of the fields declared by its class or its ancestor classes.

Note

Fields are also referred to as "instance variables.” I prefer the term “fields” for several reasons: “instance variables” is redundant since there are no class variables, it is ambiguous since it could mean variables that are instances, just “variables” would be more ambiguous, and “fields” is shorter. (An alternative term is ...

Get Objective-C Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.