Word of Runtime 1

This chapter describes how the message expressions are converted into objc_msgSend function calls, and how you can refer to methods by name.

...

It then explains how you can take advantage of objc_msgSend, and how—if you need to—you can circumvent dynamic binding.

...

In Objective-C, messages aren’t bound to method implementations until runtime.

...

This function takes the receiver and the name of the method mentioned in the message—that is, the method selector—as its two principal parameters.

take ... as ...

Any arguments passed in the message are also handed to objc_msgSend

...

It first finds the procedure (method implementation) that the selector refers to

...

Since the same method can be implemented differently by separate classes, the precise procedure that it finds depends on the class of the receiver

...

The key to messaging lies in the structures that the compiler builds for each class and object

...

Every class structure includes these two essential elements

...

This table has entries that associate method selectors with the class-specific addresses of the methods they identify

...

This pointer, called isa, gives the object access to its class and, through the class, to all the classes it inherits from

...

These elements of class and object structure are illustrated in Figure 3-1

...

Successive failures cause objc_msgSend to climb the class hierarchy until it reaches the NSObject class

...

Caches grow dynamically to accommodate new messages as the program runs

...

These arguments give every method implementation explicit information about the two halves of the message expression that invoked it

...

The pointer that methodForSelector: returns must be carefully cast to the proper function type

...

The first two arguments passed to the procedure are the receiving object (self) and the method selector (_cmd). These arguments are hidden in method syntax but must be made explicit when the method is called as a function

...

Using methodForSelector: to circumvent dynamic binding saves most of the time required by messaging. However, the savings will be significant only where a particular message is repeated many times, as in the for loop shown above

...

你可能感兴趣的:(Word of Runtime 1)