views:

714

answers:

2

Hi everyone, I would appreciate some help with something I working on and have not done before now and having some proplems because I don't think I understand exactly how to do this. What I'm wanting to do i'm sure is simple to most all of you and will be to me as soon as I do it the first time correctly....anyway.... I have a tableview that I'm needing to populate with two things, a username and a number with a count of items (the username could be a primary key). Currently I have a tableview populating and editable with an array....no problem....I know how to do that.

The two parts I need help with understanding is to:

  1. read a plist with these two values into a dictionary, and read them into two different arrays that I can use with my tables.

  2. Save the arrays back to the dictionary and then back to a plist.

I think I'm getting the most confused with how to store these two things in dictonary keys and values. I've looked that over but just not "getting it".

I would appreciate some short code examples of how to do this or a better way to accomplish the same thing.

As always, thanks for your awesome help....

A: 

The approach that would perhaps be the simplest is to store the data as an array of dictionaries. This has the issue that recreating the array from a plist with mutable leaves is convoluted at best.

But if you can tolerate the performance hit of replacing dictionaries when updating the list instead of modifying them, it might definitely be the simplest course of action.

This also has the added benefit that your datasource only needs to deal with one array, and that the whole shebang would be Key-Value Compliant, which might further simplify your code.

Williham Totland
A: 

You can use NSArray method writeToFile: atomically: to dump your data into a file, you can then use initWithContentOfFile to retrieve the information from t hat file just as you dumped it previosly. I believe if you have dictionaries in your array you should be able to get them back this way. You can always use core data as well for storage if you find your structures to store are getting complex and dumping the in a file and getting them back to recreate some o bjects is becoming messy.

Daniel