Hi,

I've a "PresetsController" which holds a dictionary containing preset settings 
for my application. The presets contain trees (Mutable Dictionaries) of keys.
To save the GUI code from bothering with tracking the current preset, I want to 
give my PresetController the option to replace a keyPath like 
@"current.parameter.subparameter.value" to 
@"preset2.parameter.subparameter.value".
I implemented it with a valueForUndefinedKey:
- (id) valueForUndefinedKey:(NSString *)key {
        if ([key isEqual:@"current"])
                return [presets valueForKey:currentPreset]; //presets is a 
NSMutableDicitonary, currentPreset a NSString
        else
                return [presets valueForKey:key];
}

, returning the dictionary belonging to the current preset. This works for 
setting and reading using keyPaths. It does not work for observing a keyPath 
like @"current.parameter.subparameter.value". How should I implement that? I 
tried monitoring all keyPaths in the dictionaries, and than calling [self 
will/didChange] like:
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
change:(NSDictionary *)change context:(void *)context {
        NSString *newKeyPath=[keyPath 
stringByReplacingOccurrencesOfString:currentPreset withString:@"current"];
        
        if ([keyPath hasPrefix:currentPreset]) {
                if ([[change 
valueForKey:NSKeyValueChangeNotificationIsPriorKey] boolValue])
                        [self willChangeValueForKey:newKeyPath];
                else
                        [self didChangeValueForKey:newKeyPath];
        }
}

but this doesn't trigger anything. If I replace newKeyPath with @"current" than 
all observers will get a trigger, independent of any (sub)parameters.
What would be the correct way to trigger the observers?

Kind regards,

Remco Poelstra

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to