views:

520

answers:

1

When I generate my classes from CoreData entities I get generated methods

@interface Site (CoreDataGeneratedAccessors)
- (void)addSearchesObject:(Search *)value;
- (void)removeSearchesObject:(Search *)value;
- (void)addSearches:(NSSet *)value;
- (void)removeSearches:(NSSet *)value;

@end

So my question is pretty simple when I call removeSearchesObject:myObject do I have to delete it too ?

[site removeSearchesObject:[[fetchedResultsController fetchedObjects] objectAtIndex:indexPath.section]];
     [context deleteObject:[[fetchedResultsController fetchedObjects] objectAtIndex:indexPath.section]];

Here is the generated code (from the doc)

- (void)removeEmployeesObject:(Employee *)value

{

    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];



    [self willChangeValueForKey:@"employees"

          withSetMutation:NSKeyValueMinusSetMutation

          usingObjects:changedObjects];

    [[self primitiveEmployees] removeObject:value];

    [self didChangeValueForKey:@"employees"

          withSetMutation:NSKeyValueMinusSetMutation

          usingObjects:changedObjects];



    [changedObjects release];

}
+1  A: 

Yes, if you remove the object you still need to delete it. The system doesn't know if you are going to reattach it somewhere else. On the other hand, if you delete the object it will remove itself so long as the delete rule in your model is set to "Nullify." For more info you should check out the documentation on delete rules.

Louis Gerbarg
Thanks ! It's what I believed
Fsdn