Re: [問題] override superclass init時會call的fun

看板MacDev作者 (Bang!)時間11年前 (2012/11/29 07:07), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/2 (看更多)
既然你sample code都寫出來了 實驗看看就知道啦 如果你在A的init中的[self xxx]丟一個breakpoint 然後創建一個b 就會發現即使你進到A的method裡 "self"永遠都還是B 既然B override了A的xxx method [self xxx]自然就是call B的method囉 ※ 引述《wfgh (lyle)》之銘言: : 如果我override superclass的init裡會call的method : 那[super init]時會call新的method還是原來的? : ex: : ClassA:NSObject : - (id)init : { : self = [super init]; : [self xxx]; : return self; : } : - (void)xxx : { : do something : } : ClassB:ClassA : - (id)init : { : self = [super init] //這裡會call A的xxx還是B的xxx呢? : return self; : } : - (void)xxx : { : override...... : }_ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 199.2.242.199

11/29 19:55, , 1F
原po是問 [super init] 不是問 [self init], 兩者不同
11/29 19:55, 1F

11/29 23:19, , 2F
是[super init]沒錯阿
11/29 23:19, 2F
文章代碼(AID): #1GjfbFDl (MacDev)
文章代碼(AID): #1GjfbFDl (MacDev)