• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Invoking the superclass from a private method correctly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Invoking the superclass from a private method correctly
      • From: Dave Camp <email@hidden>
    • Re: Invoking the superclass from a private method correctly
      • From: j o a r <email@hidden>
  • Prev by Date: Re: NSCalendarDate picker widget?
  • Next by Date: Re: NSDocument setFileName - File Must Exist?
  • Previous by thread: Re: NSToolbar(item) quirk
  • Next by thread: Re: Invoking the superclass from a private method correctly
  • Index(es):
    • Date
    • Thread