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: Sandor Szatmari <email@hidden>
- Date: Fri, 17 May 2013 07:07:32 -0400
If you go the dictionary route a simple category on NSDictionary would allow you to compute dynamic properties such as area = length * width.
Sandor Szatmari
On May 17, 2013, at 1:43, Trygve Inda <email@hidden> wrote:
> I need to keep a small (few thousand) record database of sorts. Each record
> has some pre-detertermined fields, but the user can add there own fields to
> to a limited extent. It is a pretty light use so CoreData isn't what I
> really want, plus migrating to future structures is an issue with CoreData.
>
> This will be simple objects in an NSMutableArray.
>
> I can use an array of NSMutableDictionaries or perhaps an array of
> class-based custom cocoa objects.
>
> One nice thing about the object route is that I can have some fields
> (properties) be based on a calculation rather than real storage like they'd
> be in an NSMutableDictionary.
>
> E.g.
>
> NSNumber length
> NSNumber width
> NSNumber area
>
> In an object area could be a method returning length*width instead of an
> instance var for area.
>
> The trouble comes in the fact that I need to be able to add properties at
> runtime. For the dictionary option, it is easy - just make sure the key
> names don't collide and I can add more keys to each dictionary.
>
> But for the objects I don't see a nice way to do this
>
> There is setValue:forUndefinedKey: and then each object could keep a local
> dictionary of these "defined at runtime" keys.
>
> Thoughts on this?
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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