• 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: [self init] vs. [super init] in initWithCoder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [self init] vs. [super init] in initWithCoder


  • Subject: Re: [self init] vs. [super init] in initWithCoder
  • From: Jim Correia <email@hidden>
  • Date: Fri, 18 Aug 2006 07:50:38 -0400

On Aug 17, 2006, at 11:39 PM, Greg Hurrell wrote:

init and initWithCoder are two different pathways for initializing an object. They're independent and I don't think one should call the other, and I've never felt the need to. I think this is explained fairly well in the docs. But sometimes there are things that you would want to do in both cases, and for that reason I often use this pattern:

- (void)commonInit
{
	// stuff that is common to both init and initWithCoder:
}

The limitation with using such a generic method name as -commonInit for your class's common private initialization is that no one else in the class hierarchy can use that same method name without unintended side effects.


Since this is an unacceptable limitation, and since it isn't necessary that the private common initializer have a "pretty" method name, an easy out is to just give it an ugly, unique name, based on the class name:

- (void)MyFanceWidget_commonInit
{

}

Jim

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >[self init] vs. [super init] in initWithCoder (From: John McLaughlin <email@hidden>)
 >Re: [self init] vs. [super init] in initWithCoder (From: Greg Hurrell <email@hidden>)

  • Prev by Date: Custom NSButtonCell and NSTableColumn binding
  • Next by Date: What's the fastest way to get icons for file/folders?
  • Previous by thread: Re: [self init] vs. [super init] in initWithCoder
  • Next by thread: Re: [self init] vs. [super init] in initWithCoder
  • Index(es):
    • Date
    • Thread