Re: NSMutableDictionary or Custom Object when adding properties?
Re: NSMutableDictionary or Custom Object when adding properties?
- Subject: Re: NSMutableDictionary or Custom Object when adding properties?
- From: Jens Alfke <email@hidden>
- Date: Fri, 17 May 2013 11:28:16 -0700
On May 16, 2013, at 11:41 PM, Graham Cox <email@hidden> wrote:
>> There is setValue:forUndefinedKey: and then each object could keep a local
>> dictionary of these "defined at runtime" keys.
>
> There are low-level runtime methods that allow you to add properties at runtime. I'm not sure whether that's considered good practice, but it's doable.
MYDynamicObject is a class I wrote that enables this:
https://github.com/snej/MYUtilities/blob/master/MYDynamicObject.h
You can subclass this, add properties to the @interface, and then mark them as @dynamic in the @implementation. Then you just need to implement a generic getter and setter method to do something like store the value in an internal mutable dictionary.
(This is just like what NSManagedObject does with @dynamic properties, only in a more generic form.)
—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