Why no -[NSManagedObjectContext deleteObjects:] ?

  • NSManagedObjectContext implements a deleteObject: method which
    deletes a single object.  What if I want to delete an array or set of
    objects?  Since CoreData is so High Level and Efficient, I would
    expect there to be an optimized deleteObjects: method.

    It just seems weird that I should have to enumerate through and
    deleteObject: for each.  I'm a little worried that maybe I'm thinking
    inside the wrong box or something.

    Thanks,

    Jerry Krinock
  • On Sep 1, 2007, at 9:20 AM, Jerry Krinock wrote:

    > NSManagedObjectContext implements a deleteObject: method which
    > deletes a single object.  What if I want to delete an array or set
    > of objects?  Since CoreData is so High Level and Efficient, I would
    > expect there to be an optimized deleteObjects: method.
    >
    > It just seems weird that I should have to enumerate through and
    > deleteObject: for each.  I'm a little worried that maybe I'm
    > thinking inside the wrong box or something.

    You could add a "deleteYourself:" method to all the objects the use
    NSArray's

    - (void)makeObjectsPerformSelector:(SEL)aSelector;

    If it would make you feel better.

    Scott
  • On Sep 1, 2007, at 7:20 AM, Jerry Krinock wrote:
    > NSManagedObjectContext implements a deleteObject: method which
    > deletes a single object.  What if I want to delete an array or set
    > of objects?  Since CoreData is so High Level and Efficient, I would
    > expect there to be an optimized deleteObjects: method.

    Deleting an object from a managed object context is relatively cheap
    as it does not impact the persistent store.  That is, deletion is
    "just" editing the object graph in memory as maintained by the context.

    The real expense comes at the point in time the changes contained in
    the managed object context are committed to the underlying store.  At
    that point, CoreData can optimize how the set of changes are committed
    to the underlying persistent store(s).

    b.bum
  • > Deleting an object from a managed object context is relatively cheap
    > as it does not impact the persistent store.

    But not when it comes to bindings. Deleting one object will send
    notifications around. I have to unbind an NSArrayController and then bind it
    back up after the enumeration in order to perform a delete of several
    objects. NSManagedObject should definitely have a deleteObjects: to avoid
    that issue. All that said I would recommend you file an enhancement request
    with Apple's bug tracker.

    Conor
  • On Sep 2, 2007, at 4:14 AM, Conor wrote:
    >> Deleting an object from a managed object context is relatively cheap
    >> as it does not impact the persistent store.
    >
    > But not when it comes to bindings. Deleting one object will send
    > notifications around. I have to unbind an NSArrayController and then
    > bind it
    > back up after the enumeration in order to perform a delete of several
    > objects. NSManagedObject should definitely have a deleteObjects: to
    > avoid
    > that issue. All that said I would recommend you file an enhancement
    > request
    > with Apple's bug tracker.

    The model layer should not add API to optimize a behavior of the
    control layer.  Instead, the control layer should provide mechanisms
    for optimized interaction with the underlying model layer.

    And, indeed, it appears that NSArrayController has API to do exactly
    that:

    - (void)remove:(id)sender;    // overridden to remove the selected
    objects
    ...
    - (void)removeObjectAtArrangedObjectIndex:(unsigned int)index;    //
    removes from the content objects and the arranged objects (as
    specified by index in the arranged objects)
    - (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes;
    - (void)removeObject:(id)object;    // removes from the content
    objects and the arranged objects (if currently contained)
    - (void)removeObjects:(NSArray *)objects;
    ...

    I have no idea if said methods are optimized for efficient interaction
    with the model layer (haven't parsed that code in a while), but -- if
    not -- they would be a much more appropriate target for a bug report
    than filing an enhancement request against the model layer (CoreData).

    b.bum
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