Newbie CoreData help needed

Discussion in 'Mac Programming' started by kselbee, Jun 21, 2008.

  1. macrumors newbie

    Apr 1, 2008
    I have created a project in XCode and then created a User model with a firstName and lastName properties (strings). Then I go to my nib (xib actually) and add an ArrayController and set the mode to Entity and the EntityName to User to use my user model. I check the Prepares Content and Editable check boxes. The app will run at this point, but doesn't do much yet. But then I try to set the Managed Object Context and bind to File's Owner and set Model Key Path to managedObjectContext. Once I do this, the app no longer runs... it just bounces in the dock. I am following the directions from a tutorial so I think I am doing this right. Can anyone please help? Thanks....
  2. macrumors G4


    Nov 3, 2005
    Go to Xcode>Run>Console and see what it says.

    Also is the program document based or not?
  3. thread starter macrumors newbie

    Apr 1, 2008
    The app is not document based... is this a problem? I don't want multiple docs... just 1. Here's what the console says....

    [Session started at 2008-06-21 08:59:04 -0400.]
    2008-06-21 08:59:04.404 CoreDataTest1[5557:10b] Cannot perform operation without a managed object context

    The Debugger has exited with status 0.
    [Session started at 2008-06-21 08:59:25 -0400.]
    2008-06-21 08:59:26.030 CoreDataTest1[5562:10b] An uncaught exception was raised
    2008-06-21 08:59:26.031 CoreDataTest1[5562:10b] [<NSApplication 0x112360> valueForUndefinedKey:]: this class is not key value coding-compliant for the key managedObjectContext.
    2008-06-21 08:59:26.032 CoreDataTest1[5562:10b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSApplication 0x112360> valueForUndefinedKey:]: this class is not key value coding-compliant for the key managedObjectContext.'
  4. macrumors 6502a

    Mar 13, 2008
    the easiest way to set up core data....

    Create a new project of "core data document based spotlight importer" type. (name might not be exactly that)

    Edit your model, adding all your properties and all that. Save.

    Open mydocument.xib and delete the label on the window.

    Drag a core data entity from the library into the window. Select your project and data model, and fool around with the options after that.

    When you finish, it will give you an array, or more if necessary. All the bindings will be done for you, and you can inspect them if you wish to learn from them. You will have all this stuff set up, and all you have to do is build and run now!
  5. macrumors G4


    Nov 3, 2005
    ^^ You don't want the spotlight one.

    The reason you're having true is that you are sending the managedObjectContext request to the wrong object/binding. But I'm not sure why its doing that...
  6. macrumors member


    Sep 28, 2007
    I've figured it out. The problem is that you're binding the Array Controller to File's Owner… but File's Owner is used primarily only for document-based applications. If you look in your Interface Builder doc window, there should automatically be an appName_AppDelegate object (I'm using Snow Leopard, YMMV). Simply bind the Array Controller's Managed Object Context to this AppDelegate object instead of to File's Owner.

    I was having the same problem, and this worked for me. :)
    Thanks @Eraserhead!
  7. macrumors newbie

    Dec 16, 2010
    @simpl_beep, thank you, thank you thank you!! 2 days of tearing my hair out til I saw the File Owner thing.

Share This Page