감사합니다. 아마도 그렇게 할 것입니다.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(managedObjectContextDidChange:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:managedObjectContext];
2.) 변경이 발생할 때 직원이 업데이트되는 :
1.) 변경에 대한 알림을 등록 : 한편 나는이 일을 다른 방법을 발견했다. 그 객체가 부서 0 관계가 있는지 확인하고 삭제 :
- (void)managedObjectContextDidChange:(NSNotification *)notification {
NSSet *updatedObjects = [[notification userInfo] objectForKey:NSUpdatedObjectsKey];
for(NSManagedObject *obj in updatedObjects){
// walk through updated objects -> check for employees
// check if they still contain departments and if not delete them
if([obj.entity.name isEqualToString:@"Employee"]){
NSLog(@"Employee changed!");
if([[(Employee*)obj Departments] count]==0){
NSLog(@"No more relations -> Delete Employee");
[managedObjectContext deleteObject:obj];
}
}
}}
를 너무 잘 작동하지만, 행동의 종류를 관찰하기위한 여러 기관이있는 경우 더 복잡 얻을 수 있습니다.
Cocoa Touch 또는 Snow Leopard를 사용하는 경우이 논리를 부서의'-prepareForDeletion' 메소드에 넣을 수 있습니다. –
나는 이것이 더 좋은 해결책이라고 생각한다. 고마워! – Nick
부서를 말할 때 NSManagedObject 호출 부서를 의미합니까? – Ricardo