One Quickie


Handling unknown keys with KVC (Bindings->General)
Override valueForUndefinedKey::
- (id) valueForUndefinedKey: (NSString *) key
{
    id value;
    value = [self lookUpValueUsingSomeOtherMechanism: key];

    if (value == nil) {
        value = [super valueForUndefinedKey: key];
    }

    return (value);

} // valueForUndefinedKey
Some handy uses for this is using the user defaults for storing values (you can use the key directly to [NSUserDefaults stringForKey:], or use it to query the contents of an NSDictionary

The counterpart for this is

- (void) setValue: (id) value forUndefinedKey: (NSString *) key, which you can use to stash stuff into user prefs or a dictionary.



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com