Re: On more newbie question about init...
Re: On more newbie question about init...
- Subject: Re: On more newbie question about init...
- From: Andrew Pinski <email@hidden>
- Date: Fri, 13 Jun 2003 23:34:55 -0400
On Friday, Jun 13, 2003, at 23:16 US/Eastern, Scott Andrew wrote:
I am writing my own -initWithFileContents for my objects. The base
class does nothing but store the file name they were loaded from. But
for my image class I have the following:
-(id)initWithFileContents:(NSString*) filePath
{
if (self = [super initWithFileContents:filePath])
{
image = [[NSImage alloc] initWithContentsOfFile:filePath];
if (image == nil)
{
[self release];
return nil;
}
}
return self;
}
Is it OK to call release on self like this to fail out of the imbedded
object doesn't create?
Yes and this is the recommended way of doing it.
Remember init and release are just regular messages (methods) like any
other messages (methods) and self
is not constant (unlike this in C++).
Thanks,
Andrew Pinski
_______________________________________________
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.