Hi,

I'm a little confused about a setup involving core data, bindings, NSArrayControllers and an NSCollectionView. Things were fine before I used core data:

- I have an NSCollectionView, where each view item represents a KNBox, which contains a list of KNDesktopThings, represented by a table - I have subclassed NSCollectionView, so that each view item receives its own NSArrayController, to which I bind the table - I have also subclassed NSCollectionViewItem and made each item the datasource of its table to implement drag and drop for the table - before using core data, each view item would accept a drop, create a new thing and add it to the array controller
- this worked perfectly

Now, with core data, things are a bit different:

- I have a data model with boxes and things. Things are related to boxes via a "boxItems" relation
- here is how I set up the array controller (beware, this is CocoaRuby):

    arrayController.setEntityName("KNDesktopThing")
    arrayController.setContent(box.boxItems)

- here is what I do when I accept a drop and want to create a new thing:

    managedObjectContext = NSApp.delegate.managedObjectContext
newThing = NSEntityDescription .insertNewObjectForEntityForName_inManagedObjectContext ("KNDesktopThing", managedObjectContext)
    box.addBoxItemsObject(newThing)
    arrayController.setContent(box.boxItems)

This works, but especially the last two lines make me wonder if I'm not doing things the wrong way here. Is there a way I can set things up so that I either:

- only add the new thing to the arrayController, which would hopefully update the relation, or - only add the new thing to the relation, which would hopefully update the array controller.

Why do I want to use core data? Because I hope it will give me "free" saving and undo.

Cheers,
Knud

-------------------------------------------------
Knud Möller, MA
+353 - 91 - 495086
Smile Group: http://smile.deri.ie
Digital Enterprise Research Institute
  National University of Ireland, Galway
Institiúid Taighde na Fiontraíochta Digití
  Ollscoil na hÉireann, Gaillimh

_______________________________________________

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