How does Objective-C provide a “dynamic” runtime? What does “dynamic” refer to here?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In one sentence: Objective-C decides which method implementation to call right before doing so (during runtime). The idea is that the connection between the name of a method and the implementation is dynamic. C++ for example resolves names during compile time.
Example:
In this example the
intValuemessage is first sent to an instance ofNSStringand then to anNSNumber. The code emitted by the compiler is identical for both calls–in fact the compiler does not even know to which kind of object it’s sending messages to (as the type isid).The runtime decides which implementation to call to extract an int value from a string or an
NSNumber.