Root Classes
A root class is one with no parent class. Objective-C allows multiple root classes, but you are most likely to use one supplied with your compiler.
All Objective-C distributions provide a root class called Object
. This section describes the Object
supplied with the GNU runtime. The
Object
class provided by Darwin is
similar, but Darwin users will be more likely to use the NSObject
root class that comes with the
Cocoa class library. (The GNUstep library also provides an NSObject
root class almost identical to
Cocoa’s.) This section describes the fields and methods of both Object
and NSObject
.
Both classes provide access to Objective-C features like reflection, memory management, and archiving. Most of the classes you write will inherit from one of these classes, so your objects will be able to use these features.
Note
The runtime goes to some length to make class objects behave the same as regular objects. In particular, they appear to inherit their fields and methods from the root classes, so they share in the properties described in this section.
Fields
Both Object
and NSObject
declare
only one field, isa
, whose type is Class
. This field is inherited by all their
descendants, which is critical to the operation of inheritance and
message dispatch. It points to the class object representing the
instance’s class. See Section
1.9 earlier in this book.
Methods
Root class methods are accessible from any object that derives from the class—usually all regular objects in a program. ...
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.