作者ksksBangBang (Bang!)
看板MacDev
标题Re: [问题] override superclass init时会call的fun
时间Thu Nov 29 07:07:56 2012
既然你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
1F:推 offname:原po是问 [super init] 不是问 [self init], 两者不同 11/29 19:55
2F:→ ksksBangBang:是[super init]没错阿 11/29 23:19