• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMutableDictionary or Custom Object when adding properties?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSMutableDictionary or Custom Object when adding properties?
      • From: Trygve Inda <email@hidden>
References: 
 >NSMutableDictionary or Custom Object when adding properties? (From: Trygve Inda <email@hidden>)
 >Re: NSMutableDictionary or Custom Object when adding properties? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: CTFramesetterSuggestFrameSizeWithConstraints cuts off text
  • Next by Date: Re: NSMutableDictionary or Custom Object when adding properties?
  • Previous by thread: Re: NSMutableDictionary or Custom Object when adding properties?
  • Next by thread: Re: NSMutableDictionary or Custom Object when adding properties?
  • Index(es):
    • Date
    • Thread