Whoops, fixed observer handling

CQTexperiment
Chris Moeller 2013-10-21 11:24:48 -07:00
parent 63fba5930e
commit 9c660b593a
1 changed files with 12 additions and 3 deletions

View File

@ -49,11 +49,17 @@
}]; }];
theDecoders = sortedDecoders; theDecoders = sortedDecoders;
theDecoder = nil; theDecoder = nil;
cachedObservers = [[[NSMutableArray alloc] init] autorelease]; cachedObservers = [[NSMutableArray alloc] init];
} }
return self; return self;
} }
- (void)dealloc
{
[cachedObservers release];
[super dealloc];
}
- (NSDictionary *)properties - (NSDictionary *)properties
{ {
if ( theDecoder != nil ) return [theDecoder properties]; if ( theDecoder != nil ) return [theDecoder properties];
@ -97,6 +103,9 @@
{ {
if ( theDecoder != nil ) { if ( theDecoder != nil ) {
[theDecoder close]; [theDecoder close];
for (NSDictionary *obsItem in cachedObservers) {
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
}
[theDecoder release]; [theDecoder release];
theDecoder = nil; theDecoder = nil;
} }
@ -114,14 +123,14 @@
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", options, @"options", context, @"context", nil]]; [cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", options, @"options", context, @"context", nil]];
} }
/* And this is currently called after the decoder is closed */
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath - (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
{ {
if ( theDecoder != nil )
[theDecoder removeObserver:observer forKeyPath:keyPath];
for (NSDictionary *obsItem in cachedObservers) for (NSDictionary *obsItem in cachedObservers)
{ {
if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) { if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) {
[cachedObservers removeObject:obsItem]; [cachedObservers removeObject:obsItem];
break;
} }
} }
} }