On Mar 1, 2010, at 08:48, Joanna Carter wrote:

> Actually, I don't really want a "dependent" property. All I want is a way to 
> be able to pass a property on the main controller class to each of three 
> derived array controllers, so that they can use that value to set a property 
> on every new item added to the array controller.
> 
> At the moment, I am manually passing the value to each of the array 
> controllers in the windowControllerDidLoadNib: method of the main controller.
> 
> This is fine but, since I will need to do the same thing in other scenarios, 
> I wanted to create a derived array controller component that I could add to a 
> NIB and setup in IB, rather than having to write the hookup code every time.
> 
> - (void)windowControllerDidLoadNib:(NSWindowController *)windowController 
> {
>  [super windowControllerDidLoadNib:windowController];
> 
>  [myExtendedArrayController setExtraProperty:[self extraProperty]];
> 
>  ...
> }

You want to "pass a property"? What does that mean? Never mind -- it's clear 
from your second paragraph that you mean "pass a value". I'm rudely pointing 
this out because using precise terms precisely is important, and you've led 
yourself astray multiple times in this thread by using them imprecisely.

If you don't really want a dependent property, then you certainly don't want a 
binding. Bindings are a more complicated version of a dependent property.

You can achieve what you said above very simply. The cheap version goes like 
this:

-- Add an IBOutlet to your NSArrayController subclass. Call it (say) 
owningWindowController. Or anything you like that doesn't conflict with an 
existing name.

-- When you instantiate one of these custom array controllers in IB, connect 
its owningWindowController outlet to File's Owner.

-- In your custom array controller's awakeFromNib method, do the following:

        myExtraProperty = [owningWindowController extraProperty];

That's it.

The classy version is only slightly more complicated:

-- Define a protocol. Call it (say) extraPropertyProviderProtocol. The protocol 
contains just one thing, the "extraProperty" property definition.

-- Have your window controller formally adopt the protocol. (It already 
implements it.)

-- Declare your custom array controller outlet as IBOutlet 
NSObject<extraPropertyProviderProtocol>* extraPropertyProvider.

-- Connect the outlet to File's Owner, as before.

-- In your custom array controller's awakeFromNib method, do the following:

        myExtraProperty = extraPropertyProvider.extraProperty;

That way, File's Owner isn't unnecessarily constrained to be a particular class 
of object. It can be any object that conforms to the protocol.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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