• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Basic info about outlets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic info about outlets


  • Subject: Re: Basic info about outlets
  • From: Graham Cox <email@hidden>
  • Date: Thu, 15 May 2008 21:53:19 +1000

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@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

_______________________________________________

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


  • Follow-Ups:
    • Re: Basic info about outlets
      • From: Torsten Curdt <email@hidden>
References: 
 >Basic info about outlets (From: "John Love" <email@hidden>)

  • Prev by Date: Re: iPhone SDK List?
  • Next by Date: Re: Flash'In'App – Free Cocoa Framework
  • Previous by thread: Basic info about outlets
  • Next by thread: Re: Basic info about outlets
  • Index(es):
    • Date
    • Thread