Re: Creating a class cluster
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.