Skip navigation.
 
mlwiring up core data, bindings, NSArrayController and NSCollectionView
FROM : Knud Hinnerk Möller
DATE : Tue Feb 26 20:09:14 2008

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

Related mailsAuthorDate
mlwiring up core data, bindings, NSArrayController and NSCollectionView Knud Hinnerk Mölle… Feb 26, 20:09
mlRe: wiring up core data, bindings, NSArrayController and NSCollectionView Philip Bridson Feb 26, 20:23