【问题标题】:CoreDataGeneratedAccessors - removeObject does delete the object?CoreDataGeneratedAccessors - removeObject 确实删除了对象?
【发布时间】:2010-12-15 10:03:29
【问题描述】:

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

}

【问题讨论】:

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


    【解决方案1】:

    是的,如果您删除了对象,您仍然需要将其删除。系统不知道您是否要将其重新附加到其他地方。另一方面,如果您删除对象,只要模型中的删除规则设置为“无效”,它就会自行删除。有关更多信息,您应该查看documentation 上的删除规则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多