问题 CoreDataGeneratedAccessors - removeObject会删除对象吗?


当我从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];

}

7267
2017-11-11 10:27


起源



答案:


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


12
2017-11-11 11:37



谢谢 !这就是我所相信的 - Fsdn


答案:


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


12
2017-11-11 11:37



谢谢 !这就是我所相信的 - Fsdn