Hi. I guess many have already stumped into this one, but my wildest phrasing 
attempts in web-searches didn't yield. 

I'd like to have a "data" object, similar to (but much simpler than) CoreData 
entity, which only exports a bunch of properties. Something like

@interface MSPersonalData :NSObject 
{
}
-(id) initWithData:(NSDictionary*)initialData;
-(id) init;
@property (nonatomic, retain) NSString* firstName;
@property (nonatomic, retain) NSString* lastName;
@property (nonatomic, retain) NSDate*   birthDate;
@property (nonatomic, retain) NSNumber* salary;
@end

I'd like this object to have NO ivars, and NO property implementations, not 
even synthesized. Instead I'd like the object to either inherit from 
NSMutableDictionary or own a single NSMutableDictionary ivar, and I'd like any 
access to my object to be transparently translated to internal dictionary 
valueForKey: and setValue:forKey:.

Simply put, I'd like code like this: 

MSPersonalData *myDataObject = ;[MSPersonalData alloc] init];
myDataObject.firstName = @"Motti"; 

to actually perform 

[self  setValue:@"Motti" forKey: @"firstName"]; // if MSPersonalData inherits 
NSMutableDictionary
or
[internalDictionary  setValue:@"Motti" forKey: @"firstName"]; // if 
MSPersonalData owns  NSMutableDictionary. 

Such object can be very useful for UI binding,  and as self-documented API for 
a sub-system. Instead of declaring a set of static keys as string, just behave 
as if there were iVars per each key of the object. I think CoreData 
NSManagedObjects do this, in their "primitive" implementation.

I tried several schemes for implementation, but all became cumbersome, and I 
had to do much trickery, and in the end it looked ugly. I strongly feel there 
must be a simple and elegant way to do this. To have a mutable dictionary react 
to the "syntactic sugar" of dot notation.

Is there a good, general solution for this?

Motti Shneor,
Spectrum Reflections Ltd.


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to