NSArrayController (or NSObjectController) in Entity Mode

  • I'd like to programmatically create an NSArrayController that fetches
    a specific entity from my Managed Object Context.

    I'm using the following :

    mFutureRecordingsArrayController = [[NSArrayController alloc] init];
    [mFutureRecordingsArrayController setManagedObjectContext:[[NSApp
    delegate] managedObjectContext]];
    [mFutureRecordingsArrayController setEntityName:@"Schedule"];

    However if I get the description of the
    mFutureRecordingsArrayController in gdb it says :

    Printing description of mFutureRecordingsArrayController:
    <NSArrayController: 0x3ee2d0>[object class: NSMutableDictionary,
    number of selected objects: 0]

    However an object controller created in IB says :

    Printing description of mCurrentSchedule:
    <NSObjectController: 0x3541c0>[entity: Schedule]

    An email thread from mmalc in February of this year
    (http://lists.apple.com/archives/cocoa-dev/2007/Feb/msg01140.html)
    suggests that the above should work fine (I've tried the
    setManagedObjectContext/setEntityName calls in both the above order
    and reversed with no change in results).

    Is there some other (undocumented ?) set of messages I need to create
    an NSArrayController in Entity Mode ? Or can it only be done through
    IB ? Sure I can create the controller in IB and 'link it up' - but
    shouldn't this be possible to do in code too ?

    Andrew 8-)
  • if you want a specific entity could you use nsobjectcontroller instead of
    nsarraycontroller?  in your example you compare the description of a
    nsarraycontroller (created programatically) to the description of a
    nsobjectcontroller (created in IB).  since the former is a collection of
    objects it would seem to me that the description would be different.

    +Clint
  • On Sep 2, 2007, at 10:41 AM, Andrew Kimpton wrote:

    > I'd like to programmatically create an NSArrayController that
    > fetches a specific entity from my Managed Object Context.
    > [...]
    > However if I get the description of the
    > mFutureRecordingsArrayController in gdb it says :
    > Printing description of mFutureRecordingsArrayController:
    > <NSArrayController: 0x3ee2d0>[object class: NSMutableDictionary,
    > number of selected objects: 0]
    >
    The description is misleading if the controller was not created in IB.
    Is the controller not working in any other way?

    mmalc
  • Quoting mmalc crawford <mmalc_lists...>:

    >
    > On Sep 2, 2007, at 10:41 AM, Andrew Kimpton wrote:
    >
    >> I'd like to programmatically create an NSArrayController that
    >> fetches a specific entity from my Managed Object Context.
    >> [...]
    >> However if I get the description of the
    >> mFutureRecordingsArrayController in gdb it says :
    >> Printing description of mFutureRecordingsArrayController:
    >> <NSArrayController: 0x3ee2d0>[object class: NSMutableDictionary,
    >> number of selected objects: 0]
    >>
    > The description is misleading if the controller was not created in IB.
    > Is the controller not working in any other way?

    Ahhh.... having seen the bad description I 'gave up' and didn't pursue
    things further. Debugging bindings is tricky enough - 'knowing' I had
    a bad controller didn't inspire me with any confidence to proceed
    further.

    I'll replace the IB reated Controller with one created in code and
    'just see what happens'.

    Does anyone recall if this misleading description logged as a bug ? If
    not I'll write it up.

    > mmalc

    Andrew 8-)
  • On Sep 6, 2007, at 12:05 PM, Andrew Kimpton wrote:
    > Does anyone recall if this misleading description logged as a bug ?
    > If not I'll write it up.
    >
    It's now written up...

    mmalc
  • Andrew,

    I posted this same issue back in February. I never got it fully working.

    In my case, a NSObjectController set to be in Entity mode in a nib file behaved differently than an identical one created in code.

    Besides the misleading description you mentioned, the controller would not register as an editor with the managed context when a text field bound to the controller began editing.

    I wanted this to work to ensure that changes made in the text field were persisted when the managed context were saved without leaving the text field. My workaround for this was to set the first responder to nil anytime the managed context was saved.

    Sent via BlackBerry by AT&T

    -----Original Message-----
    From: Andrew Kimpton <awk...>

    Date: Thu, 06 Sep 2007 15:05:01
    To:mmalc crawford <mmalc_lists...>
    Cc:<cocoa-dev...>
    Subject: Re: NSArrayController (or NSObjectController) in Entity Mode

    Quoting mmalc crawford <mmalc_lists...>:

    >
    > On Sep 2, 2007, at 10:41 AM, Andrew Kimpton wrote:
    >
    >> I'd like to programmatically create an NSArrayController that
    >> fetches a specific entity from my Managed Object Context.
    >> [...]
    >> However if I get the description of the
    >> mFutureRecordingsArrayController in gdb it says :
    >> Printing description of mFutureRecordingsArrayController:
    >> <NSArrayController: 0x3ee2d0>[object class: NSMutableDictionary,
    >> number of selected objects: 0]
    >>
    > The description is misleading if the controller was not created in IB.
    > Is the controller not working in any other way?

    Ahhh.... having seen the bad description I 'gave up' and didn't pursue
    things further. Debugging bindings is tricky enough - 'knowing' I had
    a bad controller didn't inspire me with any confidence to proceed
    further.

    I'll replace the IB reated Controller with one created in code and
    'just see what happens'.

    Does anyone recall if this misleading description logged as a bug ? If
    not I'll write it up.

    > mmalc

    Andrew 8-)
  • Andrew,

    I posted this same issue back in February. I never got it fully working.

    In my case, a NSObjectController set to be in Entity mode in a nib file behaved differently than an identical one created in code.

    Besides the misleading description you mentioned, the controller would not register as an editor with the managed context when a text field bound to the controller began editing.

    I wanted this to work to ensure that changes made in the text field were persisted when the managed context were saved without leaving the text field. My workaround for this was to set the first responder to nil anytime the managed context was saved.

    Sent via BlackBerry by AT&T

    -----Original Message-----
    From: Andrew Kimpton <awk...>

    Date: Thu, 06 Sep 2007 15:05:01
    To:mmalc crawford <mmalc_lists...>
    Cc:<cocoa-dev...>
    Subject: Re: NSArrayController (or NSObjectController) in Entity Mode

    Quoting mmalc crawford <mmalc_lists...>:

    >
    > On Sep 2, 2007, at 10:41 AM, Andrew Kimpton wrote:
    >
    >> I'd like to programmatically create an NSArrayController that
    >> fetches a specific entity from my Managed Object Context.
    >> [...]
    >> However if I get the description of the
    >> mFutureRecordingsArrayController in gdb it says :
    >> Printing description of mFutureRecordingsArrayController:
    >> <NSArrayController: 0x3ee2d0>[object class: NSMutableDictionary,
    >> number of selected objects: 0]
    >>
    > The description is misleading if the controller was not created in IB.
    > Is the controller not working in any other way?

    Ahhh.... having seen the bad description I 'gave up' and didn't pursue
    things further. Debugging bindings is tricky enough - 'knowing' I had
    a bad controller didn't inspire me with any confidence to proceed
    further.

    I'll replace the IB reated Controller with one created in code and
    'just see what happens'.

    Does anyone recall if this misleading description logged as a bug ? If
    not I'll write it up.

    > mmalc

    Andrew 8-)
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