Removing an Observer

In NSManagedObject Sub Class, I have code ...

- (void) awakeFromInsert { 
[self addObserver:[NSApp delegate] forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil]; 
}

What adds my App Delegate as an observer, what I want to do now, from within my App Delegate, I want to remove myself as an observer for my NSManagedObject Sub Class.

How should I do it? Thank.

I was thinking of adding this to my App Delegate.

[JGManagedObject removeObserver:self forKeyPath:@"name"];

but, unfortunately, is removeObserver:forKeyPath:not a class method.

+1
source share
3 answers

- . , - , ( ) .

. , , , , , . , , . - ( ), . , , , :

- (void)dealloc
{
  [self removeObserver:[NSApp delegate] forKeyPath:@"name"];
  // other clean-up
  [super dealloc];
}

, , .

+4

, :

// Given some managed object "object"...
[object removeObserver:self forKeyPath:@"name"];

, self , , [NSApp delegate], .

+1

How about sending your object to a message removeObserver:forKeyPathbefore removing it from ManagedObjectContext?

0
source

All Articles