Re: NSArrayController Added /Removed Objects
Re: NSArrayController Added /Removed Objects
- Subject: Re: NSArrayController Added /Removed Objects
- From: Keary Suska <email@hidden>
- Date: Mon, 03 Jun 2013 19:23:52 -0600
On Jun 3, 2013, at 10:31 AM, Richard Somers wrote:
> I have a programmatic NSArrayController wired up to a Core Data managed object context. I need to know what objects are added or removed from arrangeObjects.
>
> I have tried using KVO but that did not work. When KVO is used to observe arrangedObjects, the notification only indicates that the content has changed. It does not indicated what objects were added or removed.
>
> I thought about overriding some of the NSArrayController add / remove methods and identifying which objects are added or removed. But when objects are added to the managed object context, the only NSArrayController method that gets called is setContent:. None of the add or insert methods are called.
>
> It is interesting to note that when objects are removed from the managed object context, some of the NSArrayController remove methods are called but setContent: is not called. This is just the opposite of what happens when adding objects to the managed object context.
>
> Does anyone have any insight on how to determine what objects are added or removed from an NSArrayController?
Purely from KVO, not really. If you can guarantee that your context is "clean" (i.e. no changes) you can query the context for changes. Otherwise, if you implement the MO subclass and provide unordered accessors for the relationship and trap the changes there. If it isn't a relationship you would need to implement an intermediary controller with unordered accessors for the entity.
HTH,
Keary Suska
Esoteritech, Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden