Programatically bind NSArrayController to NSManagedObjectContext?

  • Is there any way to bind an NSArrayController to an
    NSManagedObjectContext without using Interface Builder?  See the ???:

    [arrayController bind:@"managedObjectContext"
                  toObject:managedObjectContext
              withKeyPath:@"???"
                  options:nil] ;

    NSManagedObjectContext is not listed in the Cocoa Bindings Reference
    [1].  Is this really a "binding", or is it something else?  The
    documentation for binding NSArrayController 'managedObjectContext' in
    [1] calls it "registered with".

    Here's maybe a clue:
        NSLog(@"Bindings for moc: %@", [managedObjectContext
    exposedBindings]) ;
    Says this:
        CBindings for moc: ()

    Thanks again,

    Jerry

    [1] http://developer.apple.com/documentation/Cocoa/Reference/
    CocoaBindingsRef/index.html
  • On Sep 30, 2007, at 7:35 AM, Jerry Krinock wrote:

    > Is there any way to bind an NSArrayController to an
    > NSManagedObjectContext without using Interface Builder?  See the ???:
    > [arrayController bind:@"managedObjectContext"
    > toObject:managedObjectContext
    > withKeyPath:@"???"
    > options:nil] ;
    >
    And again, why is this any different to any other binding?  It's just
    a key path.
    In this case, though, if you're not binding through any other object,
    why not just set it directly (setManagedObjectContext:)?

    > NSManagedObjectContext is not listed in the Cocoa Bindings Reference
    > [1].  Is this really a "binding", or is it something else?  The
    > documentation for binding NSArrayController 'managedObjectContext'
    > in [1] calls it "registered with".
    >
    It's not clear what this means.
    Bindings are bindings.

    mmalc
  • On 2007 Sep, 30, at 8:43, mmalc crawford wrote:

    > And again, why is this any different to any other binding?  It's
    > just a key path.
    > In this case, though, if you're not binding through any other
    > object, why not just set it directly (setManagedObjectContext:)?

    Ah, very good.  When I saw that it was called a "binding" in
    Interface Buildero I went into the Cocoa Bindings Reference looking
    for a binding.  In this case, there is none, and indeed as you
    suggested the only way do it is by setting directly:

    [arrayController setManagedObjectContext:xxx] ;
    [arrayController setEntityName:yyy] ;
    [arrayController prepareContent] ;

    >> NSManagedObjectContext is not listed in the Cocoa Bindings
    >> Reference [1].  Is this really a "binding", or is it something
    >> else?  The documentation for binding NSArrayController
    >> 'managedObjectContext' in [1] calls it "registered with".
    >>
    > It's not clear what this means.
    > Bindings are bindings.

    Well, I would say that the code I entered above is not a binding
    because it does not, and could not, invoke
    bind:toObject:withKeyPath:options.  However, the effect is indeed the
    same and I guess it doesn't matter what we call it.

    Thanks, mmalc.  My programatically-instantiated array controller is
    working with my moc now.
  • On Sep 30, 2007, at 4:36 PM, Jerry Krinock wrote:

    > [arrayController setManagedObjectContext:xxx] ;
    > [arrayController setEntityName:yyy] ;
    > [arrayController prepareContent] ;
    >>> NSManagedObjectContext is not listed in the Cocoa Bindings
    >>> Reference [1].  Is this really a "binding", or is it something
    >>> else?  The documentation for binding NSArrayController
    >>> 'managedObjectContext' in [1] calls it "registered with".
    >> It's not clear what this means.
    >> Bindings are bindings.
    > Well, I would say that the code I entered above is not a binding
    > because it does not, and could not, invoke
    > bind:toObject:withKeyPath:options
    >
    It's again not clear what this means.
    The code you wrote above is, obviously, not a binding -- you're
    setting the managed object context directly using an accessor method.
    You can, however, bind the 'managedObjectContext' binding of
    controllers -- it is common(*), for example, in a document-based
    application to bind it to [TheDocument].managedObjectContext.

    If you wanted to do this in, say, the implementation of
    windowControllerDidLoadNib in a subclass of NSPersistentDocument it
    would look like:

    [arrayController bind:@"managedObjectContext"
                toObject:self
              withKeyPath:@"managedObjectContext"
                  options:nil] ;

    (*) Largely because it's easy to do and code-free..

    mmalc
previous month september 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
Go to today