• 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: Ondra Cada <email@hidden>
  • Date: Mon, 29 Jul 2002 01:14:23 +0200

On Sunday, July 28, 2002, at 05:46 , Ondra Cada wrote:

Nope. You don't ever (well, for a relative newbie) implement your own alloc. Here, you just exploit the fact (discussed in this list shortly ago)
that init can change the instance:

// your base class implementation
#import "HiddenSubclass1.h"
#import "HiddenSubclass2.h"

@implementation Foobar
-initWithString:(NSString*)s {
if (!(self=[super init])) return nil;
[self autorelease];
return [[[HiddenSubclass1 alloc] initWithString:s] autorelease]; // WRONG
}
-init {
if (!(self=[super init])) return nil;
[self autorelease];
return [[[HiddenSubclass2 alloc] init] autorelease]; // WRONG
}
...

Sorry, this was wrong: in case of init, you *don't* autorelease. Mea maxima culpa.
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.
References: 
 >Re: Creating a class cluster (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: cocoa-dev digest, Vol 2 #1008 - 12 msgs
  • Next by Date: Specifying a class which conforms to a protocol
  • Previous by thread: Re: Creating a class cluster
  • Next by thread: Re: Creating a class cluster
  • Index(es):
    • Date
    • Thread