• 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: Q: Designated initializers: what are they?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q: Designated initializers: what are they?


  • Subject: Re: Q: Designated initializers: what are they?
  • From: Izidor Jerebic <email@hidden>
  • Date: Sat, 12 May 2001 10:03:51 +0200

On Saturday, May 12, 2001, at 09:45 AM, email@hidden wrote:


Now, the reason for my confusion is that initWithFrame: is supposed to be the "designated initializer" for the NSView class. Doesn't that mean that that's the one method that's always going to be called eventually, no matter what other initializers get called? Since that's (apparently) not the case, what does it mean to be a "designated initializer"? And am I supposed to duplicate my initialization code in every possible initializer, i.e. initWithFrame: and initWithCode:, or is there a more elegant solution?

The designated initializer will allways be called when you create new object. That is true.

But when you read an object from file (such as loadNibSection does), you do not create new objects - you restore old objects. In this case -initWithCoder: will be called.

In case your AppKit object needs to do some interaction with the environment (such as registering for drag and similar), you should probably put these things into a separate method and call it from both -init... (whatever the designated initializer is) and -awakeFromNib (which gets called after the nib file with your object is loaded).

izidor


References: 
 >Q: Designated initializers: what are they? (From: email@hidden)

  • Prev by Date: Q: Designated initializers: what are they?
  • Next by Date: Re: Q: Designated initializers: what are they?
  • Previous by thread: Q: Designated initializers: what are they?
  • Next by thread: Re: Q: Designated initializers: what are they?
  • Index(es):
    • Date
    • Thread