Skip navigation.
 
mlRe: Basic info about outlets
FROM : Graham Cox
DATE : Thu May 15 13:53:19 2008

Yep, you're basically correct, sounds right to me.

When the nib is loaded, <documentWindow> will point to ("refer to") 
the window object.

someMethod is able to simply use the variable <documentWindow> because 
that is an instance variable of the MyDocument object, and all methods 
of MyDocument are able to use the object's ivars as if they were 
locally declared. This is one of the main reasons that OOP is a useful 
way to program.

so someMethod could then message the window itself, for example:

- (void) someMethod
{
    // set a property:

    [documentWindow setTitle:@"Arrooooggahh!!"];

    // read a property:

    NSRect wFrame = [documentWindow frame];
}


If you're asking *how* this works, the answer lies in the Obj-C 
runtime. Basically all of an object's methods are implicitly passed a 
pointer to the object itself (self) as a hidden parameter to the 
function that the method is wrapping. The compiler thus generates code 
that makes use of this implicit parameter, so the real code is really 
doing the equivalent of:

void someMethod( NSDocument* self )
{
    setTitle( self->documentWindow, @"string" );
}

underneath, it's all procedural ;-) (I'm simplifying, it's not 
literally quite like this, Find out more here: file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html)
.

hth,


G.



On 15 May 2008, at 9:30 pm, John Love wrote:

> I *think* I understand about outlets and actions .. but now I am not 
> so
> sure.
>
> Specifically, if I set (NSWindow *)documentWindow as an Outlet in my 
> main
> nib and I declare in MyDocument.h file:
>
> interface MyDocument:NSDocument {
>          IBOutlet NSWindow *documentWindow;
> }
> ...
>
> - (void) someMethod:documentWindow;
>
> and in MyDocument.m file:
>
> - (void) someMethod {
>      // some operation that accesses a property of documentWindow
> }
>
> Okay, documentWindow is typed as a outlet in the main nib and in the
> interface,.h, file ... and I have control-dragged from the FileOwner 
> to the
> title bar of the Window, selecting "documentWindow" as the Outlet. 
> But,
> just exactly HOW does the actual documentWindow object get passed so 
> that
> someMethod can look at one of its properties?
>
> This question is oriented to "behind the scenes".
>
> Thanks in advance>
>
> John Love
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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/graham.<email_removed>
>
> This email sent to graham.<email_removed>

Related mailsAuthorDate
mlBasic info about outlets John Love May 15, 13:30
mlRe: Basic info about outlets Graham Cox May 15, 13:53
mlRe: Basic info about outlets Torsten Curdt May 15, 15:21
mlRe: Basic info about outlets Graham Cox May 15, 15:32
mlRe: Basic info about outlets Mike Abdullah May 15, 15:36
mlRe: Basic info about outlets Torsten Curdt May 15, 15:53
mlRe: Basic info about outlets Erik Buck May 15, 16:08
mlRe: Basic info about outlets Graham Cox May 15, 16:13
mlRe: Basic info about outlets John Love May 17, 16:01