Return to Snippet

Revision: 16667
at August 11, 2009 21:54 by phifty


Initial Code
//
//  KVCEnabledObject.h
//

#import <Foundation/Foundation.h>


@interface KVCEnabledObject : NSObject {
    NSMutableDictionary *_metadata;
}

@end

@implementation KVCEnabledObject

- (id)init
{
    if (self = [super init]) {
        _metadata = [[NSMutableDictionary alloc] initWithCapacity:0];
    }
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if (nil != value) {
        [_metadata setValue:value forKey:key];
    }
}

- (void)setNilValueForKey:(NSString *)theKey
{
    [_metadata setValue:[NSNull null] forKey:key];
}

- (id)valueForUndefinedKey:(NSString *)key
{
    id ret = [_metadata valueForKey:key];
    return ([ret isKindOfClass:[NSNull class]]) ? nil : ret;
}

- (void)dealloc
{
    [_metadata removeAllObjects];
    [_metadata release];
    
    [super dealloc];
}

@end

Initial URL


Initial Description
This is a wrapper for objects that use Key-Value Coding (KVC) in Objective-C.  An appropriate use would be for business objects whose state changes throughout the life of the application session.

Initial Title
Lite KVC Wrapper

Initial Tags


Initial Language
Objective C