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)系作者
  • 序言:七十年代末算灸,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌扑媚,老刑警劉巖盆赤,帶你破解...
    沈念sama閱讀 222,000評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件霉祸,死亡現(xiàn)場離奇詭異脐湾,居然都是意外死亡,警方通過查閱死者的電腦和手機捧韵,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,745評論 3 399
  • 文/潘曉璐 我一進(jìn)店門市咆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人再来,你說我怎么就攤上這事蒙兰。” “怎么了芒篷?”我有些...
    開封第一講書人閱讀 168,561評論 0 360
  • 文/不壞的土叔 我叫張陵搜变,是天一觀的道長。 經(jīng)常有香客問我针炉,道長挠他,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,782評論 1 298
  • 正文 為了忘掉前任篡帕,我火速辦了婚禮殖侵,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘赂苗。我一直安慰自己愉耙,他們只是感情好贮尉,可當(dāng)我...
    茶點故事閱讀 68,798評論 6 397
  • 文/花漫 我一把揭開白布拌滋。 她就那樣靜靜地躺著,像睡著了一般猜谚。 火紅的嫁衣襯著肌膚如雪败砂。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,394評論 1 310
  • 那天魏铅,我揣著相機與錄音昌犹,去河邊找鬼。 笑死览芳,一個胖子當(dāng)著我的面吹牛斜姥,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播沧竟,決...
    沈念sama閱讀 40,952評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼铸敏,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了悟泵?” 一聲冷哼從身側(cè)響起杈笔,我...
    開封第一講書人閱讀 39,852評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎糕非,沒想到半個月后蒙具,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體球榆,經(jīng)...
    沈念sama閱讀 46,409評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,483評論 3 341
  • 正文 我和宋清朗相戀三年禁筏,在試婚紗的時候發(fā)現(xiàn)自己被綠了持钉。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,615評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡融师,死狀恐怖右钾,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情旱爆,我是刑警寧澤舀射,帶...
    沈念sama閱讀 36,303評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站怀伦,受9級特大地震影響脆烟,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜房待,卻給世界環(huán)境...
    茶點故事閱讀 41,979評論 3 334
  • 文/蒙蒙 一邢羔、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧桑孩,春花似錦拜鹤、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,470評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至宣虾,卻和暖如春惯裕,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背绣硝。 一陣腳步聲響...
    開封第一講書人閱讀 33,571評論 1 272
  • 我被黑心中介騙來泰國打工蜻势, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人鹉胖。 一個月前我還...
    沈念sama閱讀 49,041評論 3 377
  • 正文 我出身青樓握玛,卻偏偏與公主長得像,于是被迫代替她去往敵國和親甫菠。 傳聞我的和親對象是個殘疾皇子挠铲,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,630評論 2 359

推薦閱讀更多精彩內(nèi)容

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