Re: Getting a reference to the data model from a delegate
Re: Getting a reference to the data model from a delegate
- Subject: Re: Getting a reference to the data model from a delegate
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 19 Jan 2003 05:02:29 -0500
on 03-01-18 9:10 PM, James DiPalma at email@hidden wrote:
>
> From: Rob In der Maur <email@hidden>
>
>
>
> Now my question:
>
> I'm having problems getting a reference back to my data model from a
>
> delegate in a document based application, which also has a dedicated
>
> NSWindowController class.
To generalize what Jim said, it is common in any object-oriented programming
language to pass a reference to the creating class into the created class as
a parameter in the instantiation or initialization routine. So, in
Objective-C/Cocoa:
MYClass myInstance = [[MYClass alloc] initWithWhoever:self];
In MYClass, you declare an instance variable to hold this back-reference,
and in MYClass's -initWithWhoever: method you assign the incoming reference
to the iVar.
An alternative is to create your MYClass instance first, then simply tell it
to set the instance variable, like so:
[myInstance setMyIVar:self];
This requires, of course, that your MYClass class declares the access method
setMyIVar: to take care of the assignment.
Your question is a little confusing since you don't say (in the excerpt I
saw) whether the delegate is the NSWindowController subclass. But it doesn't
really matter.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.