CoreDataGeneratedAccessors - removeObject会删除对象吗?

时间:2009-11-11 10:27:15

标签: iphone objective-c cocoa-touch core-data

当我从CoreData实体生成我的类时,我得到生成的方法

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

@end

所以当我调用removeSearchesObject时,我的问题非常简单:myObject我是否也必须删除它?

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

以下是生成的代码(来自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 个答案:

答案 0 :(得分:12)

是的,如果删除对象,则仍需删除它。系统不知道您是否要将其重新连接到其他地方。另一方面,如果删除对象,只要模型中的删除规则设置为“Nullify”,它就会自行删除。有关详细信息,请查看有关删除规则的documentation