tags:

views:

173

answers:

3

This is a question about the inner workings of Cocoa NIB files and the supporting framework classes for them.

For a handy example, please take a look at the Apple Currency Calculator tutorial: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutorial/01Introduction/01Introduction.html

If you open the MainMenu.nib file, you will see an object representing "Converter Controller".

When the app runs, an instance of the ConverterController class is instantiated by something in the app (something in the NIB, or the framework supporting the NIB).

(Don't confuse this with the other class, Converter, which has its instance created by the code in ConverterController.)

My question is, what creates this instance of ConverterController? Is it the default File's Owner object in the NIB? Whatever object creates the instance, what is the code that that object uses? There must be some method/function somewhere in the NIB or framework saying:

ConverterController *someVarName = [[ConverterController alloc] init];

I want to see that code, the specific code that is currently being used to create the ConverterController instance.

I don't want to know how to create a replacement for the ConverterController instance, or in general how to manually instantiate class instances related to a NIB file.

+2  A: 

A nib is an archive of objects. They're created in Interface Builder, and when the nib is loaded, the objects in it are unarchived and linked up.

Chuck
This is not an untrue statement.
Nibbles
But would those mysteriously voting up the answer please note -- it is a statement only tangentially related to the question I asked.
Nibbles
It is directly related. You asked what creates the instance — I answered that Interface Builder does it. There's no "code in the nib" — the nib is just an archive. That's the answer.
Chuck
Thank you -- didn't mean that ad hominem. Something is initializing the external controller object ConverterController (which if I'm not mistaken is only linked and not archived itself). This may well be one of the archived objects in the NIB, after it unarchives and starts doing its work.
Nibbles
+1  A: 

Take a look at the Resource Programming Guide document in the developer docs. The section on Nib files is a good overview, and the sub-section "Built-In Support For Nib Files" explains how nib files get loaded in a number of cases.

Nathan
+1  A: 

Have a look at the Info.plist file.

One of the sections in there is for the Main Nib file name. This is the nib that is unarchived when the application starts. Usually, this is MainMenu.xib.

Because the controller object is within this main nib file, it is created when the nib file is unarchived.

Abizern