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

...

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,174評論 0 23
  • 今天被朋友拉去看了這部據(jù)說評分很高的泰國電影,十分驚艷。 這部電影講述的是一名天才,如何在特殊的社會(huì)環(huán)境中,在種種...
    Aegean亦清閱讀 392評論 0 1
  • 我愿赤手空拳打天下,也愿遠(yuǎn)遠(yuǎn)的祝福你,不求你能明白,但求心安,有一種深情叫你幸福就好。 我會(huì)揮手告別,不帶走一片云彩。
    shuxiyi閱讀 217評論 0 0

友情鏈接更多精彩內(nèi)容