开发者

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 didChangeVal开发者_运维知识库ueForKey:@"employees"

          withSetMutation:NSKeyValueMinusSetMutation

          usingObjects:changedObjects];



    [changedObjects release];

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜