Re: File's Owner
Re: File's Owner
- Subject: Re: File's Owner
- From: Erik Buck <email@hidden>
- Date: Fri, 23 May 2008 12:30:16 -0700 (PDT)
What programming experience do you have? Perhaps I can explain File's Owner in terms of some other framework you already know ?
You use the Files Owner proxy in each nib file to enable connections or key paths to objects that are not instantiated within that nib file. Interface Builder needs an icon for you to drag such connections to and from. Files Owner is just such an icon. First Responder is another such Icon. Any connections or key paths that involve the Files Owner icon will be established with whatever object is specified as the owner when the nib file is loaded via + loadNibNamed:owner:. The MainMenu.nib file is loaded automatically by the framework by calling code similar to [NSBundle loadNibNamed:@MainMenu owner:NSApp]; Does that line of code mean anything to you ?
Nib files can be loaded at any time while an application is running, and the same nib file can be loaded multiple times creating new copies of all objects within the nib each time. Can you see how it is useful to be able to make connections to objects that are not instantiated within the same nib file ? Consider how NSDocument loads nib files that define the objects representing each document instance.
@implementation MYDocument : NSDocument
{
IBOutlet NSTextField *someTextFiledInMyAssocoatedNibFile;
}
- (NSString *)windowNibName
{
Return @MYNibFile;
}
@end
At some point, you will create a MyDocument instance and as part of its initialization it will execute a line of code like the following:
[NSBundle loadNibNamed:[self windowNibName] owner:self];
Because the MYDocument instance is the owner specified when the nib is loaded, any connection made within the nib to the someTextFiledInMyAssocoatedNibFile outlet will be connected to the instance of MYDocument that loaded the nib file.
When you open a second document, it will also call [NSBundle loadNibNamed:[self windowNibName] owner:self]; except the self refers to the second instance of MYDocument. Loading the nib file twice creates two copies of every object within the nib file, but the connections made to Files Owner within the nib file are established to the two different instances of MYDocument.
P.S.
You say "I don't know what object loaded my nib, so that does not help me" and then immediately quote the documentation which says "In MainMenu.nib, this is the application instance, which is a shared singleton instance of NSApplication which is also set to the global variable NSApp." The documentation explicitly tells you that in the case of the MianMenu.nib file, the Files Owner is a proxy for an instance of the NSApplication class.
You then say "how all applications can share this is beyond me". This indicates to me that you don't know what a Singleton is and dont know what a Proxy is and don't know what a global variable is and don't know that with Unix (e.g. Mac OS X) applications do not generally share global variables.
It's no wonder you are struggling with Cocoa. You are apparently not a C programmer, not aware of common object oriented patterns like the Singleton, and not familiar with Unix. In my opinion, C programming, pattern awareness, and basic operating system familiarity are all prerequisites to learning Cocoa.
_______________________________________________
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