NSMutableDictionary or Custom Object when adding properties?
NSMutableDictionary or Custom Object when adding properties?
- Subject: NSMutableDictionary or Custom Object when adding properties?
- From: Trygve Inda <email@hidden>
- Date: Thu, 16 May 2013 22:43:22 -0700
- Thread-topic: NSMutableDictionary or Custom Object when adding properties?
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