Need Help with Bindings and Core Data...

  • I have been trying to solve this problem for a while now but I guess I
    just don't understand the bindings well enough to figure out what I'm
    doing wrong...

    I have a Core Data model that is bound to a main window which contains
    details of the data.  It uses the standard generated AppDelegate to
    grab the data and setup the persistent store, the managed object
    context and the the managed object model... If the file exists it
    displays the data.  If the file doesn't exist it gives me a blank
    screen.  That seems like the right actions...

    Part of my process includes importing data from an old Access Database
    and populating the CoreData Model.  As part of this process I want to
    remove the current store and basically load the old data migrate it to
    a new file using CoreData and then go back to the main window and have
    it display the new store.

    So, the steps I take before doing the migration are as follows...

    I release the managedObjectContext
    I release the persistentStore
    I delete the existing file...
    I recreate the managedObjectContext which in turn reloads the
    persistentStore

    Unfortunately I get no data in the window...  So I played around a bit
    with creating an object on the Array Controller that is controlling
    the screen inside Interface Builder.  It works fine when it first
    comes up but even after trying to re-initialize the binding to the new
    managedObjectContext I still get no luck...  Here is a portion of my
    code...

        url = [NSURL fileURLWithPath: [[coreDataDelegate
    applicationSupportFolder] stringByAppendingPathComponent:
    @"Namaste.sql"]];

        if ( [fileManager fileExistsAtPath:[url path]] ) {
      NSLog(@"Namaste.sql exists!\n");
           /* Shutdown the current Core Data Set... */
      [coreDataDelegate releasePersistentStore];
      [fileManager removeItemAtPath:[url path] error:&error];
      /* Restore the main Core Data Set... */
      [coreDataDelegate managedObjectContext];
      [coreDataDelegate restoreControllerBinding];
        }

    NSManagedObjectContext *moc = [coreDataDelegate managedObjectContext];

    The releasePersistentStore is as follows...

    -(void)releasePersistentStore {

        [managedObjectContext release], managedObjectContext = nil;
        [persistentStoreCoordinator release], persistentStoreCoordinator
    = nil;
    }

    And the restoreControllerBinding is as follows...

    -(void)restoreControllerBinding {
    [clientArrayController bind:@"contentObject" toObject:self
    withKeyPath:@"managedObjectContext" options:nil];
    }

    Any help would be appreciated... :)

    Mike
  • > -(void)restoreControllerBinding {
    > [clientArrayController bind:@"contentObject" toObject:self
    > withKeyPath:@"managedObjectContext" options:nil];
    > }

      ... it seems like this is your problem. Have you read what the
    "contentObject" binding is? From the docs:

    "An NSArrayController that the NSArrayController treats as its content."

      Perhaps you meant to bind the array controller's
    **managedObjectContext** to self's managedObjectContext?

    --
    I.S.
  • Thanks I.S...

    That did the trick...  Seems I better find the doc you are talking
    about and read it...

    Mike

    On Dec 28, 2007, at 11:42 AM, I. Savant wrote:

    >
    >> -(void)restoreControllerBinding {
    >> [clientArrayController bind:@"contentObject" toObject:self
    >> withKeyPath:@"managedObjectContext" options:nil];
    >> }
    >
    > ... it seems like this is your problem. Have you read what the
    > "contentObject" binding is? From the docs:
    >
    > "An NSArrayController that the NSArrayController treats as its
    > content."
    >
    > Perhaps you meant to bind the array controller's
    > **managedObjectContext** to self's managedObjectContext?
    >
    > --
    > I.S.
    >
    >
    >
    >
    >
  • > That did the trick...  Seems I better find the doc you are talking
    > about and read it...

      Google "NSArrayController bindings" and you'll find it in short
    order. For each control and controller, there's a corresponding "Cocoa
    Bindings Reference ..." document. The name of the object and
    "bindings" in your search string will get you straight there via Google.

    --
    I.S.
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today