From: Adam R. M. <ama...@ma...> - 2007-06-14 16:30:38
|
On Thursday, June 14, 2007, at 08:28AM, "Christiaan Hofman" <cmh...@gm...> wrote: >I am very much confused by the behavior of super. I thought it always >referred to the instance 'self' referring to the implementation of >its superclass to look up methods. So what happens if I re-assign >self, does it still refer to the current self with the superclass's >implementation of the current self? Or does it somehow stick with the >superclass of the original self? That's an interesting problem. My read of the docs for objc_msgSendSuper is that the objc_super structure is generated at compile time when a super keyword is found. Since you're changing the immediate superclass at runtime, I think super would still point to the original superclass. >Let me give the concrete problem. In -[PDFAnnotation >initWithDictionary:], I did something like: > >... >self = [[SKPDFAnnotationNote alloc] initWithBounds:bounds]; >... >[(PDFAnnotationText *)super setIconType:iconType]; >... > >This gave me a run time error, saying that SKPDFAnnotationNote does >not implement -setIconType. Even though it inherits it from its >superclass (and moreover I call super, sot self, so why would it even >look in SKPDFAnnotation's implementation?) As to why the error says SKPDFAnnotationNote doesn't implement setIconType:, I don't know. It might be interesting to override -doesNotRecognizeSelector: in both classes and see what the call sequence is (or maybe just look at when the exception is raised). -- adam |