NSArrayController Added /Removed Objects

  • 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?

    Thanks,
    Richard Somers
  • 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.
previous month june 2013 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