1

I'm trying to create a data structure for three fields. One method can grab two fields from a sqlite database. Another method grabs data using the two fields from another sqlite database. What is a good way to store the data? The three fields I need are of type:

NSString, key: @"Name"
NSInteger, key: @"ID"
NSArray, key: @"Info"

I thought I would do an array of dictionaries. So in the first method, I get the NSString and NSInteger, create a dictionary, and create an array of those dictionaries out of it. Then I got stuck thinking how I even print out the data for a NSMutableDictionary with two keys (question #1).

Then the second thing I thought was, can I then use the Name, ID fields to get the other piece of data from another table, and add a new key/value pair into the dictionary. I wasn't sure if that could be done (question #2).

And I didn't know if there was just a better way to approach this with a different data structure (question #3).

Thanks!

2
  • What do you mean by "print out"? You can, of course, use description to do a "diagnostic dump" of the whole structure, but if you want to print things in a nice, defined format you need write the logic to do it. Basically no more difficult with NSDictionarys/NSArrays that with regular C-style structures, though. Commented Oct 12, 2011 at 23:21
  • @DanielRHicks Yeah I was trying to print out the values for the NSDictionary when there are multiple keys. Commented Oct 13, 2011 at 15:09

1 Answer 1

1

Create a class for the data items, an iVar for each Name, ID, Info. Then you have a lot of flexibility.

While an NSDictionary initially often seems to be an easy solution it is generally better to create a class which is really rather easy and usability is generally better.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.