• 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: On more newbie question about init...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >On more newbie question about init... (From: Scott Andrew <email@hidden>)

  • Prev by Date: Cocoa's custom class delegate conventions
  • Next by Date: Re: On more newbie question about init...
  • Previous by thread: On more newbie question about init...
  • Next by thread: Re: On more newbie question about init...
  • Index(es):
    • Date
    • Thread