0

How can I get notifications with NSNotificationCenter when object is added to NSMutableDictionary?

Also are there any notifications for immutable NSDictionary?

Shadowfax
  • 1,567
  • 2
  • 13
  • 16
  • 1
    **of course not.** but you can write an own inherited class from `NSDictionary` and you can override the relevant methods and it can post the extra notification for you at any time. – holex Aug 03 '12 at 13:28

1 Answers1

1

The the beauty of inheritance :)

#define kSomeDictionarySetAValue @"SomeDictionarySetAValue"

@interface SomeDictionary : NSMutableDictionary

@end

@implementation SomeDictionary

- (void) setValue:(id)value forKey:(NSString *)key
{
    [super setValue:value forKey:key];

    [[NSNotificationCenter defaultCenter] postNotificationName:kSomeDictionarySetAValue
                                                        object:self];
}

@end
jerrylroberts
  • 3,419
  • 23
  • 22