Runtime Environment
When your Objective-C program is running, certain structures and services are always set up for you, even though you don’t specifically ask for them. These serve as the counterpart to the compiler: together the compiler and the runtime implement the features that Objective-C adds to C. Most languages include runtime environments; Objective-C is distinctive in exposing a good part of its runtime in a public programming interface.
The runtime’s interfaces are in header files that will be present in any installation of gcc. (For example, in Darwin they reside at /usr/include/objc. Check your compiler’s default include paths to locate these files.) You can also download the source code for the runtime; examining it is a good way to learn more about how dynamic languages are implemented.
Class Objects
Class objects are objects that represent at runtime the classes a program is using. Because they function in the same way as regular objects—you can send them messages and use them in expressions—Objective-C unifies the treatment of classes and their instances.
Class objects are also called factory objects, because in their
most common usage you send them the +alloc message to create other objects.
Class objects are set up by the Objective-C compiler and
initialized at runtime before your code needs to use them. To get a
class object from an instance, use the -class method. For example, given an instance created this
way:
Circle*c= [Circlenew];
you can retrieve the class ...
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