Re: How to implement an object whose properties are really dictionary entries.
Re: How to implement an object whose properties are really dictionary entries.
- Subject: Re: How to implement an object whose properties are really dictionary entries.
- From: Jens Alfke <email@hidden>
- Date: Wed, 11 Jul 2012 08:49:28 -0700
On Jul 11, 2012, at 7:03 AM, Dave DeLong <email@hidden> wrote:
> You'll have to override +resolveInstanceMethod: to figure out what the user is trying to do: get or set. You'll use the selector passed in to derive the key under which you're storing the data in the dictionary. With this information, you construct a block of the appropriate signature, capturing whatever information you need, and turn it into an IMP using imp_implementationWithBlock(). You can then add that method to the class using class_addMethod().
I implemented this as part of the CouchCocoa library (and yes, it is pretty tricky). I tried to factor it so the base class is generic, and should be exactly what the OP is looking for:
https://github.com/couchbaselabs/CouchCocoa/blob/master/Model/CouchDynamicObject.h
https://github.com/couchbaselabs/CouchCocoa/blob/master/Model/CouchDynamicObject.m
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden