Invoking the superclass from a private method correctly
Invoking the superclass from a private method correctly
- Subject: Invoking the superclass from a private method correctly
- From: Nick Zitzmann <email@hidden>
- Date: Thu, 3 Feb 2005 10:39:30 -0700
I have a question for the runtime wranglers out there... I checked the
archives and didn't see anything that would answer this question...
I have a project that has several private methods, and some of these
private methods exist in concrete subclasses that need to call the
private method in the superclass. I could just write [super
someMethod], but the compiler complains about that because the method
isn't defined anywhere. I already noticed that calling [super
performSelector:] winds up generating an infinite loop. So I wrote this
category method for NSObject...
- (id)performSelectorInSuperclass:(SEL)aSelector withObject:(id)anObject
{
struct objc_super superclass;
superclass.receiver = self;
superclass.class = [self superclass];
NSAssert(superclass.class, @"-performSelectorInSuperclass: can't be
called on a root class");
return objc_msgSendSuper(&superclass, aSelector, anObject);
}
The problem is, if this method is called in a class's superclass, then
an infinite loop occurs because [self superclass] returns the class's
superclass instead of the class's superclass's superclass, so
objc_msgSendSuper() ends up calling the same method over again.
How do I acquire the appropriate superclass to call?
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden