NSArrayController "Auto Rearrange Content" causes "Cannot remove an observer for key path" error

67 views
Skip to first unread message

Tristan Celder

unread,
Jun 25, 2009, 10:50:43 AM6/25/09
to coco...@lists.apple.com
Hi,

I've been fighting an issue for some time now which seems to rear its
head when I set Auto Rearrange Content to true on an
NSArrayController. Whenever I do this it seems to throw a 'Can't
remove an observer <x> for key path "x". It always occurs when I am
trying to access a relationship of the entity I am managing within an
array controller, yielding the following kind of error Cannot remove
an observer <NSTableBinder 0x1660e130> for the key path "person.name"
from <NSManagedObject 0x1b62b0>, most likely because the value for the
key "person" has changed without an appropriate KVO notification being
sent. Check the KVO-compliance of the NSManagedObject class.

Also, this only happens with a specific scenario: when I re-open a
saved document with exactly one row of the entity being managed by the
auto rearranged array controller.

Is there something I must do with CoreData to ensure KVO compliance
when using auto rearrange content? I have a small project I've created
to demonstrate this issue if anyone would care to take a look...

Any help, greatly appreciated...
_______________________________________________

Cocoa-dev mailing list (Coco...@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev-garchive-98506%40googlegroups.com

This email sent to cocoa-dev-ga...@googlegroups.com

Steve Steinitz

unread,
Jun 25, 2009, 6:51:01 PM6/25/09
to coco...@lists.apple.com
Hi Tristan

On 25/6/09, cocoa-de...@lists.apple.com wrote:

>Is there something I must do with CoreData to ensure KVO
>compliance when using auto rearrange content? I have a small
>project I've created to demonstrate this issue if anyone would
>care to take a look...

I've moaned about this several times on this list. The biggest
problem is not the exception itself (which I now handle by
forcing a relaunch of the app) but the fact that once the
exception occurs the app doesn't work properly: selections don't
work etc.

You can look for KVO transgressions until your eyes bleed and
still not prevent the exception. One thing that's given me some
relief is to enhance the default setters for many-to-one
relationships like this one where a Sale sets its Customer:

- (void)
setCustomer: (Customer*) customer
{
Customer * oldCustomer = [self customer];
if (nil != oldCustomer && [customer isNotEqualTo: oldCustomer])
{
[oldCustomer removeSalesObject: self];
}
[super setCustomer: customer];
}

Good luck. You might want to leverage the work you've already
done on your test project by submitting it with a bug report.
Word is Apple knows about the grief this is causing but another
report can only help.

Best regards,

Steve

Tristan Celder

unread,
Jun 26, 2009, 5:34:31 AM6/26/09
to Steve Steinitz, coco...@lists.apple.com
Hey Steve,

Thanks for your reply. Yeah, that's exactly it... the interface just
falls apart after the exception is raised. The workaround I ended up
using in the end was calling arrangeObjects manually and turning off
auto arrange content completely. Not ideal, but it works...

Cheers, Tristan.

> http://lists.apple.com/mailman/options/cocoa-dev/tristan.celder%40gmail.com
>
> This email sent to tristan...@gmail.com

Tristan Celder

unread,
Jun 26, 2009, 6:43:06 AM6/26/09
to Steve Steinitz, coco...@lists.apple.com
I've also filed a bug report 7010086 with example code attached. I
have no idea if it actually submitted however (I tried twice) as it
isn't appearing in 'my originated problems' and I am unable to search
for it... hopefully we'll get a fix.

Cheers, Tristan.

Steve Steinitz

unread,
Jun 26, 2009, 7:37:26 AM6/26/09
to Tristan Celder, coco...@lists.apple.com
Hi Tristan,

On 26/6/09, Tristan Celder wrote:

>The workaround I ended up using in the end was calling arrangeObjects
>manually and turning off auto arrange content completely. Not ideal,
>but it works...

I think that may only reduce the frequency of the exception. I
think I'm still getting the exception on manual calls to
arrangeObjects. I do it often because I refresh from the
database once a minute.

But, having said that, you've got me thinking about auto arrange content.

All the best,

Steve

_______________________________________________

Cocoa-dev mailing list (Coco...@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

Steve Steinitz

unread,
Jun 26, 2009, 7:40:05 AM6/26/09
to Tristan Celder, coco...@lists.apple.com
Hi Tristan,

On 26/6/09, Tristan Celder wrote:

>I've also filed a bug report 7010086 with example code attached. I
>have no idea if it actually submitted however (I tried twice) as it
>isn't appearing in 'my originated problems' and I am unable to search
>for it... hopefully we'll get a fix.

Thanks for taking the ball on that. I'm sure it will help.
Hopefully there's just a delay showing up in your originated problems.

Cheers,

mmalc Crawford

unread,
Jun 26, 2009, 1:38:46 PM6/26/09
to Cocoa Developers

On Jun 26, 2009, at 3:43 AM, Tristan Celder wrote:

> I've also filed a bug report 7010086 with example code attached. I
> have no idea if it actually submitted however (I tried twice) as it
> isn't appearing in 'my originated problems' and I am unable to
> search for it... hopefully we'll get a fix.

For those following along, this is now
<rdar://problem/7010996> NSArrayController 'Auto rearrange content'
raises KVO exception for NSManagedObjects

mmalc

Reply all
Reply to author
Forward
0 new messages