• 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
Re: Creating a class cluster
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a class cluster


  • Subject: Re: Creating a class cluster
  • From: Shawn Erickson <email@hidden>
  • Date: Sun, 28 Jul 2002 17:54:48 -0700

On Sunday, July 28, 2002, at 05:04 PM, David Newberry wrote:

Thanks to all who responded to my question. I've got it pretty much working, but still am experiencing some oddness... maybe. Just for ease I took all the code out of my superclass and lived with the "incomplete implementation" warnings. However, I have to put code like this inthe superclass:

- (MyClass *)initWithInfo:(id)data
{
return [[MySubClass1 alloc] initWithInfo:data];
}

- (MyClass *)initWithPath:(NSString *)data
{
return [[MySubClass2 alloc] initWithPath:data];
}

If I don't have this code which forwards the messages to the subclasses, I get errors when sending an init... message to my superclass (eh '[[MyClass alloc] initWithPath@"/"]'. Is this appropriate? It seems alternatively that people have said "yes" and "no"... but chances are I just misunderstood something.

You are calling alloc (a class method) on your super class. This is creating an instance of your super class which you then send an initXxxx to. If you want to return something other then you super class then you need to implement the initXxxx methods to do so. This isn't some much forwarding as implementing things as they need to be to get done what you want to get done.

Also, from what Ondra said, do I take it that (if this code is proper), those methods should each start with "[self autorelease];"?

Yes, you need to insure the class instance that was allocated by the alloc call against your super class is freed.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: Creating a class cluster
      • From: Greg Titus <email@hidden>
References: 
 >Re: Creating a class cluster (From: David Newberry <email@hidden>)

  • Prev by Date: Re: Alternate for NSUIElement
  • Next by Date: Re: Creating a class cluster
  • Previous by thread: Re: Creating a class cluster
  • Next by thread: Re: Creating a class cluster
  • Index(es):
    • Date
    • Thread