I tried with my first ever category, which seems to work:
NSMutableDictionary+NotifiesOnEmpty.h
#import <Foundation/Foundation.h>
@interface NSMutableDictionary (NotifiesOnEmpty)
- (void)removeObjectForKeyNotify:(id)aKey;
- (void)removeAllObjectsNotify;
- (void)removeObjectsForKeysNotify:(NSArray *)keyArray;
- (void)notifyOnEmpty;
@end
NSMutableDictionary+NotifiesOnEmpty.m
#import "Constants.h"
#import "NSMutableDictionary+NotifiesOnEmpty.h"
@implementation NSMutableDictionary (NotifiesOnEmpty)
- (void)removeObjectForKeyNotify:(id)aKey {
[self removeObjectForKey:aKey];
[self notifyOnEmpty];
}
- (void)removeAllObjectsNotify {
[self removeAllObjects];
[self notifyOnEmpty];
}
- (void)removeObjectsForKeysNotify:(NSArray *)keyArray {
[self removeObjectsForKeys:keyArray];
[self notifyOnEmpty];
}
- (void)notifyOnEmpty {
if ([self count] == 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationDictionaryEmpty object:self];
}
}
@end
Don't know if that is an elegant solution, but it seems to work okay.