→ uranusjr:這和 objc_msgSend 背後的實作有關, 總之 category 如果 01/02 08:55
→ uranusjr:進行 method overriding 通常效果會是全域 01/02 08:56
→ uranusjr:總之除非你有複寫內建類別的特殊需求, 否則最好不要這樣 01/02 08:57
→ uranusjr:使用 category; 蘋果的文件有明確 discourage 這件事情 01/02 08:58
所以意思是如果我用的函式如果category裡面也有定義
我有reference該category 但不管有沒有import
它都會去跑category的那個函式嗎?
而且一個引數類型是Fraction指標 一個是id
引數名稱也不同 還是會被覆寫?
→ darktt:它的判斷依據是Method名稱,它是不管引數的 01/02 12:58
書上是說一般好像要
method name, return type, argument number, argument return types
都一樣,才有override發生
所以只要method name一樣就會被override嗎?
還是category的情況比較特殊?
→ likesea:你的書是哪一本?我的書不是這樣寫的.......... 01/03 11:00
Programming in Objective-C, 5th, page 171
You can define a new method with the same name to replace the
inherited method... A method defined with the same name as that
of a parent class replaces, or overrides, the inherited definition.
Your new method must have the same return type and take the same
number and type of arguments as the method you are overriding.
所以它後面這句是錯的嗎?
→ howdiun:因為你用id所以會覆寫 01/03 19:16
→ howdiun:對不起我錯了OTZ 01/03 19:24
→ howdiun:書中講的應該不是指category 01/03 19:26
→ howdiun:inherited是指繼承 01/03 19:28
嗯 這段是在繼承的章節裡提到
因為讀到category的時候不知道為什麼
沒有import的category裡的函式會自己跑
而且override掉main implementation裡的函式
兩個函式也沒有像書上說的完全一樣
不過我查了資料似乎它不會管類型
板友也說它不會管引數名字
和書上說的好像不同
※ 編輯: ishuen 來自: 211.76.64.68 (01/03 19:40)