Hi all -

I'm working on an app that has the concept of allowing the user to create 
templates of things which are then instanced into a document. Central to this 
is the idea that the user can create a template, then select it as part of 
another template or an instance. The relationship between template types is 
fixed. (For example, suppose one template is a tire and another is a car; the 
car has a link to a tire template; the user can select the 17"  tire template 
for the car they are working on.) 

I have an NSTableView with NSComboBoxCell's which contain lists of the other 
appropriate templates the user has created, which can be linked to the current 
template. The problem I'm having is that, if I put the templates the user can 
choose from into an array controller and source the combo box from that, the 
control wants the template to have implemented NSCopying, and then makes copies 
of it to render. A copy of the template is what ends up getting put back into 
the base template model object's pointer. So base template ends up referring to 
the other template by value, not by reference. This is a problem for me, as the 
expectation being set is that editing the template also affects the instances 
derived from it (to carry the car analogy forward, if the user uses the 17" 
tire template on three cars, then changes the tread pattern on the tire, that 
should affect those three cars with no further action.)

I've come up with two possible solutions, neither of which I like. One is to 
use the template's name as a key; that's ugly, the app currently doesn't have 
the restriction that template names have to be unique (though that's not an 
entirely unreasonable limitation). The other is to wrap the model class in a 
proxy that DOES implement NSCopying, but just contains a single pointer to the 
template instance. That's ugly since then I have to code and maintain another 
layer of indirection between the controller and the model. 

Is there a standard pattern for dealing with this situation?

Thanks!!


_______________________________________________

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 arch...@mail-archive.com

Reply via email to