• 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
Where to learn about designated initializers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Where to learn about designated initializers?


  • Subject: Where to learn about designated initializers?
  • From: Bruce Veazie <email@hidden>
  • Date: Wed, 1 Jan 2003 21:08:38 -0500

Can someone point me in the direction of documentation or books that provide information on which initializer will be called with what information for which classes when they're loaded from a nib or how it's decided which initializers will be called when loading a nib?

The question arises from the following:

In the Cocoa docs in the Memory Management topic, it states: "It's important to know the designated initializer when defining a subclass.." and does a pretty good job of explaining why that's true. However, I couldn't find particular information in general or in the class docs on "designated initializers" except for the class docs for NSView (which describes its designated initializer initWithFrame:.

Interestingly enough, the documentation on "What Happens When a Nib File is Loaded" states "Note that the init and initWithFrame: methods are never called when a nib file is opened."

In the CocoaGL example in devtools, an IB CustomView is dropped into the app window and a class MyOpenGLView is subclassed to it. In the PB project files, MyOpenGLView is subclassed to NSOpenGLView. As has been explained to me elsewhere and as I've learned from the use of some NSLogs, the "initWithFrame:" method (the designated initializer for NSView) of the subclass is, in fact, called with the dimensions of its frame in the nib when the nib is loaded, contrary to the "What Happens.." docs. This apparently happens because MyOpenGLView is not instantiated in the nib and IB has no knowledge of its implementation.

However, if, in a test case, MyOpenGLView is directly sublassed to NSOpenGLView (instead of CustomView) in the nib, and identical files to the example are used in PB, "initWithCoder:" gets called on loading instead (that method is not overridden in the example docs). Just to confuse things, the "usual" way to init NSOpenGLView is through "initWithFrame:pixelFormat:."

I vaguely understand why IB was built to do all that but my understanding certainly isn't deep enough for me to predict how other classes and subclasses may be processed.

I'm a firm believer in "Give a man a fish and he eats for a day; teach a man to fish and he eats for a lifetime" so I'd appreciate some direction to some learning materials on (what appears to be) the subtleties of this process.

Bruce

Bruce J. Veazie
email@hidden
http://veazie.org
_______________________________________________
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.

  • Prev by Date: Re: Project Builder Dec. 2002 Ignores my Breakpoints
  • Next by Date: Unarchiving Individual Windows from a Nib File
  • Previous by thread: Re: NSColor (alpha enabling and setting color in color panel)
  • Next by thread: Unarchiving Individual Windows from a Nib File
  • Index(es):
    • Date
    • Thread