0

Basically i want a data-structure that i can grow and shrink as and when i get more information on users. I want a flat associative list of usernames with their associated data E.G:

` usersDictionary = {
      user_id : {
          id : "0123456789",
          full_name : "Spongebob Jones",
          more_data: {
              likes: "snails"
          }
      },
      next_user_id : {}
  }`

Relatively new to Obj-C... I've spiked a datasource, I'm using @interface NSMutableDictionary and building up the user data appending other NSMuteablesDictionaries. All seemed well, however when trying to get the data out i'm getting:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSDictionary objectForKey:]: method only defined for abstract class. Define -[UsersCollection objectForKey:]!

I read that it's not recommended to implement NSMuteableDictionary directly, as it's a cluster class(?).

I'm looking for some advice on whether or not i'm going about this the correct way, if not please point!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Twig2let
  • 27
  • 7
  • 1
    You should never have an `@interface` that names (as the interface name and not the superclass) an iOS class. – Hot Licks Nov 26 '13 at 22:59
  • The above structure can be implemented as either a regular class (or set of classes) or a set of nested dictionaries. – Hot Licks Nov 26 '13 at 23:01

1 Answers1

1

I think you mean you're subclassing NSMutableDictionary rather than trying to redefine it.

You probably don't want to do this (scroll past my answer for the nitty-gritty details if you're interested). It is almost always more work than it is worth — simply creating a class that has an NSDictionary is usually the better approach.

Community
  • 1
  • 1
Chuck
  • 234,037
  • 30
  • 302
  • 389
  • Your linked answer regarding the cluster class makes perfect sense as to why my current implementation is broken. I'll implement as you suggested, and make use of nested dictionaries. Cheers. – Twig2let Nov 27 '13 at 20:06