I'm just curious about how people are handling the fact that when
you do
KVO, all your notifications are bottlenecked through a single method,
observeValueForKeyPath:... This is a very unpleasant and crude
architecture
(in contrast to NSNotification where, when a notification comes in,
it is
automatically routed to the selector of your choice). I really
don't want a
series of "ifs" here. I can imagine a simple dispatcher
architecture based
on NSSelectorFromString; is this the sort of thing people are
using? Thx -
m.
--
Good question; I hope this sparks more discussion.
I can think of two approaches using the context parameter, one of
which I implemented recently. In my main controller I am observing
several array controllers, where the content object types vary from
controller to controller. When the selection on any controller
changes, I get the path to a file and display it in a viewer. When
registering as an observer, I set the context to a string constant
for the key path to the file name. Here is a simplified example:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)
object change:(NSDictionary *)change context:(void *)context
{
// In awakeFromNib:, KVO registration done with context set to the
key value to retrieve.
// If it is a string (thus a path), then display it.
if (context) {
id displayPath = [object valueForKeyPath:context];
// We may get an placeholder marker or nil
if (displayPath && [displayPath isKindOfClass:[NSString class]]) {
[fileViewerController open:displayPath];
}
}
}
This worked OK for the given situation. If I had a more complex
scenario, I would consider enumerating constants to use as the
context and then use a switch() in observeValueForKeyPath:.
Something like this:
I haven't tried the second example, so it may not be as suitable as I
think. Comments?
Cheers,
Aaron
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden