4 ms·
The ClassID trick is reminiscent of ObjC's KVO addObserver:forKeyPath:options:context: - you typically pass a context to sort-out which type of object you are o
by QuadDamaged 12y ago
The ClassID trick is reminiscent of ObjC's KVO addObserver:forKeyPath:options:context: - you typically pass a context to sort-out which type of object you are observing, because the observer only has one entry point for KVO notification.
static void* kFooContext= &kFooContext
...
[foo addObserver:self forKeyPath:@"bar" options:... context:kFooContext ]
...
if(context==kFooContext){
NSFoo* foo=(NSFoo*)object;...
}
A better alternative is to use a blocks/lambda based approach, that way you can have several distinct callbacks and don't have to handle routing yourself. (see Facebook KVOController)