Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreDataGeneratedAccessors - removeObject does delete the object?

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];

}
like image 693
Fsdn Avatar asked Nov 11 '09 10:11

Fsdn


1 Answers

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.

like image 180
Louis Gerbarg Avatar answered Nov 12 '22 01:11

Louis Gerbarg