Classes
Objects in Objective-C are defined in terms of a class. New classes of objects are specializations of a more general class. Each new class is the accumulation of the class definitions that it inherits from and can expand on that definition by adding new methods and instance variables or redefining existing methods to perform new or expanded functionality. Like Java and Smalltalk, but unlike C++, Objective-C is a single inheritance language , meaning that a class can inherit functionality only from a single class.
A class is not just a blueprint for building objects; it is itself an object in the runtime that knows how to build new objects. These new objects are instances of the class.
The Root Class
Every class hierarchy begins with a root
class
that has no superclass. While it is
possible to define your own root class in Objective-C, the classes
you define should inherit, directly or indirectly, from the
NSObject class provided by the Foundation
framework. The NSObject class defines the behavior
required for an object to be used by the Cocoa framework and provides
the following functionality:
Defines the low-level functionality needed to handle object initialization, duplication, and destruction.
Provides mechanisms to aid Cocoa’s memory management model.
Defines functionality for an object to identify its class membership and provide a reasonable description of the object.
Defining a Class
In Objective-C, classes are defined in two parts, usually separated into two different ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access