Я пытался с моей первой в категории, которая, кажется, работает:
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
Не знаю, изящное ли это решение, но, похоже, оно работает нормально.