Hm ...I would have though the runtime would just do dependency/ reference injection. And the procedural code has a (hidden) reference/parameter to the object instance - that would be "self".

cheers
--
Torsten

On May 15, 2008, at 13:53, Graham Cox wrote:

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 (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/graham.cox%40bigpond.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

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/tcurdt%40vafer.org

This email sent to [EMAIL PROTECTED]

_______________________________________________

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