On May 14, 2010, at 06:43, Richard Somers wrote:

> Currently I track the selection using NSArrayController's selection methods. 
> I have a custom view that figures out what the selection should or should not 
> be and programatically sets the array controller's selection. It works very 
> well and is clean with not much code. Thus pushing the selection from the 
> view to the model is easy, just do it when the selection is pushed to the 
> array controller.
> 
> However, pulling selection changes from the model back into the array 
> controller appears to be challenging. It would seem like bindings could help 
> out here somehow. NSArrayController works with bindings and so does Core 
> Data. Why can't I simply bind the "selectionIndexes" of the array controller 
> to the "selected" model attribute. I have tried this but I can't get the 
> proper bound to object and key path to work. Perhaps NSArrayController is not 
> designed to work in this fashion.

"Does not work" doesn't give us much to go on.

If I understand you correctly, you're on the right track -- you want to bind 
the array controller's selection indexes to your data model's selection 
property. However, Core Data properties don't support index sets as a standard 
data type, so you have more work to do. Since NSIndexSet supports NSCoding, 
your easiest choice is probably to make your selection a transformable 
attribute. That means Core Data automatically converts the value to and from an 
archive using a standard transformer.

An alternative would be to try using the undefined attribute type (but it has 
to be transient). Another alternative is a full-blown custom accessor 
implementation, which is kind of a PITA to get right.


_______________________________________________

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