I am looking for a shorthand way of setting my properties directly to an NSMutableDictionary that is a instance variable. ie:
KVCModle.h:
@interface KVModel : NSObject {
NSMutableDictionary * data;
}
@property(nonatomic,assign)NSString * string1;
@property(nonatomic,assign)NSString * string2;
@end
KVCModel.m
#import "KVModel.h"
@implementation KVModel
-(id)init
{
self = [super init];
if(self)
{
data = [[NSMutableDictionary alloc] init];
}
return self;
}
-(NSString *)string1
{
return [data objectForKey:@"string1"];
}
-(NSString *)string2
{
return [data objectForKey:@"string2"];
}
-(void)setString1:(NSString *)_string1
{
[data setObject:_string1 forKey:@"string1"];
}
-(void)setString2:(NSString *)_string2
{
[data setObject:_string2 forKey:@"string2"];
}
-(void)dealloc
{
[data release];
[super dealloc];
}
@end
I have tried to override setValue:ForKey:
and valueForKey:
, but those aren't called, they allow you to directly set properties without using the property syntax.
I have made preprocessor macros to make this work in the past, but I am not interested in typing at all, and would like to avoid as much of it as I can in the future. Is there a way to make this work that I am not familiar with?
I have thought about using NSManagedObject, but I am not sure if I can get what I want out of that. EDIT: source