Reputation: 6267
What exactly are some problems that could be conquered using the runtime library in objective-c? I see no practical use for the runtime library o_o
Upvotes: 2
Views: 378
Reputation: 138031
The main problem that is conquered is making the language work. If there was no ObjC runtime library, no ObjC program could work.
The ObjC runtime library implements sending messages to objects, finding method implementations from classes, getting class data, etc. All this can't be done at compile time, and hence it needs runtime support. This need for runtime support gave birth to, well, the ObjC runtime library.
If it's related to Objective-C, chances are that the runtime library is behind it.
As the documentation states,
This shared library provides support for the dynamic properties of the Objective-C language, and as such is linked to by all Objective-C applications.
This reference is useful primarily for developing bridge layers between Objective-C and other languages, or for low-level debugging.
You may want to look at the function list. Some, like objc_msgSend
, implement behavior that you may wrongly take for granted. For instance, the call:
[foo bar:4];
actually gets compiled as:
objc_msgSend(foo, sel_getUid("bar:"), 4);
or something along these lines.
Upvotes: 8
Reputation: 104065
Zneak’s answer is spot-on. If you are curious about what can be done by calling the runtime explicitly, it’s things like reflection (finding information about classes), modifying existing classes, changing method implementations and so on, all that while your program is running.
Upvotes: 4