On 25 May '08, at 12:15 AM, Johnny Lundy wrote:

And you wonder why I am still confused. That paragraph from Apple directly contradicts what you just said.

In some cases model objects are instantiated directly in nib files, but it's not typical. It generally happens if the model object is a singleton, so there's no need to overgeneralize the code by creating instances dynamically. This most often happens in deliberately- simplified tutorial code ... like Currency Converter.

And, if I don't understand something, I will ask why. This is not magic - there is actual computer code behind that File's Owner concept, and it is deterministic, not vague, not abstract, not a philosophical enigma, not random, not ambiguous. If I had the source code I could see what it does.

It's not really complicated. "File's owner" in the nib is just a placeholder for the actual object that the nib is being loaded on behalf of at runtime. It's just like boilerplate phrases like "the party of the first part" in a legal contract.

The underlying call in NSBundle to load a nib takes an "owner" as a parameter; so NSBundle loads the nib into memory, and wherever it finds a reference in the nib to "file's owner", it just substitutes the actual "owner" object that it was given. The effect is that the IBOutlet instance variables in that owner object get filled in with pointers to objects in the nib, and other objects in the nib get pointers to the owner object.

So when an NSWindowController loads its nib, it calls [NSBundle loadNibNamed: @"MyDocument.nib" owner: self]. The nib loading process then uses the NSWindowController object wherever the nib says "file's owner". The end result is that the controller's outlets now point to view objects instantiated from the nib, and those objects have target outlets that point back to the controller.

If another window controller loads the same nib later on, it becomes the "file's owner" for that instantiation, and the new views that get loaded from the nib that time get pointed to this other controller, and vice versa.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to