#import <Foundation/Foundation.h>

static const char foo[] = "foo";
static const char* const bar = foo;

@interface Observer : NSObject
@end

@implementation Observer

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (context == bar)
    {
        NSLog(@"keyPath: %@\nobject: %p\nchange: %@\n", keyPath, object, change);
    }
    else
    {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}

@end



int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    Observer* l = [[[Observer alloc] init] autorelease];

    NSMutableDictionary* dict = [NSMutableDictionary dictionary];
    NSLog(@"dict: %p\n", dict);
    [dict addObserver:l forKeyPath:@"allValues" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:(void*)bar];

    [dict setObject:@"testValue" forKey:@"testKey"];
    [dict addObserver:l forKeyPath:@"testKey" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:(void*)bar];

    [dict setObject:@"newValue" forKey:@"testKey"];
    [dict removeAllObjects];

    [pool drain];
    return 0;
}
