2009-11-11 67 views
11

當我生成CoreData實體我的課我得到生成的方法CoreDataGeneratedAccessors - removeObject刪除對象嗎?

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

} 

回答

12

是的,如果你刪除對象,你仍然需要將其刪除。系統不知道你是否要將它重新連接到別的地方。另一方面,如果刪除對象,只要模型中的刪除規則設置爲「Nullify」,它就會自行刪除。欲瞭解更多信息,你應該檢查刪除規則documentation

+1

謝謝!這是我相信的 – Fsdn 2009-11-11 12:02:26