• 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
NSMutableDictionary or Custom Object when adding properties?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSMutableDictionary or Custom Object when adding properties?
      • From: Sandor Szatmari <email@hidden>
    • Re: NSMutableDictionary or Custom Object when adding properties?
      • From: Graham Cox <email@hidden>
    • Re: NSMutableDictionary or Custom Object when adding properties?
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: SecTrustEvaluate() failing with kSecTrustResultRecoverableTrustFailure
  • Next by Date: Re: NSMutableDictionary or Custom Object when adding properties?
  • Previous by thread: Re: disable beginSheet animation
  • Next by thread: Re: NSMutableDictionary or Custom Object when adding properties?
  • Index(es):
    • Date
    • Thread