Re: File's Owner
Re: File's Owner
- Subject: Re: File's Owner
- From: Uli Kusterer <email@hidden>
- Date: Mon, 26 May 2008 09:54:51 +0200
Am 23.05.2008 um 20:49 schrieb Johnny Lundy:
As usual, I can recite the documentation without understanding it :
File's Owner is a proxy object that is set at nib load time to the
object that loaded the nib (I don't know what object loaded my nib,
so that does not help me).
OI presume you've used other programming languages, maybe even
Carbon, where NIBs are also used? Well, in case you haven't, NIBs are
essentially "freeze-dried" object hierarchies. They describe a part of
a hierarchy, their objects and their various connections. To load
them, you usually have an object, one of the various MVC-controllers
(not necessarily NSControllers, just any NSObject subclass that
behaves as a controller as in the "Model-View-Controller" paradigm).
This object (usually called the owner of that NIB) has a method
somewhere that calls NSNibLoading to actually load the NIB file and
create objects from the description inside it.
This object must exist *before* the NIB is loaded, so it can not be
created by the NIB (can't be a blue box you drag out of the Library),
and can not be in the NIB. However, often objects inside the NIB want
to talk to the owner, so they added the File's Owner icon, which
stands in for whatever object loads the NIB. Since NIBs are kinda
generic, and don't know for sure who loads them until runtime, IB uses
whatever class you specify as the class identity for File's Owner to
decide what connections to offer you.
Unless you write your own class that loads a NIB, you'll generally
deal only with MainMenu.nib, which gets loaded by NSApplication (so
the class identity is NSApplication) and a few others, like
NSDocument, NSWindowController and NSViewController.
In MainMenu.nib, this is the application instance, which is a shared
singleton instance of NSApplication (how all applications can share
this is beyond me),
Nobody said it was shared across processes. Shared in this instance
means it is shared by everyone in the application's process, including
any libraries and plugins you load.
which is also set to the global variable NSApp (uhh, OK...).
This is probably more comprehensible if you think of it the other
way round: There is a global variable called "NSApp" which contains a
pointer to the NSApplication singleton. That way, you can call [NSApp
launchedApplications] instead of [[NSApplication sharedApplication]
launchedApplications]. Saves some typing and a method call, but isn't
good for much else.
That's all well and good, but what exactly is this thing? Why would
I succeed in having an outlet in my class if I set the Class
Identity of File's Owner to my custom class? Why should I set File's
Owner's Class Identity rather than the Class Identity of a plain
NSObject that I drag out of the Library in IB?
If you drag in a plain NSObject, that means it will create a *new*
instance. Consider you already have an object of class NSApplication
when you load the NIB. Dragging in an NSObject and settng its custom
class to NSApplication would mean that, when that NIB is loaded,
NSNibLoading would try to create a new object of that class -- in this
case, you'd have *two* application objects -- which is definitely not
what you want.
BTW -- IB 3.x also added a proxy icon for the application. In
MainMenu.nib, this means that whether you bind/connect to the File's
Owner proxy icon or the application proxy icon won't make a
difference. However, in an NSDocument's NIB, File's Owner will be set
to the NSDocument, and the application proxy will still point to the
application.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
References: | |
| >File's Owner (From: Johnny Lundy <email@hidden>) |