0

I have a table (dictionary of dictionaries) to store mapping of integers to strings. I have types and sub-types. e.g. type 1=>fruits and sub-type 1=>apple.

The mapping shall be configurable in my setting interface, but for the reset of the application, it's rather static. So I don't want to read from property-list every time I check the mapping. I'd like to only read once when program starts and only write when user changes setting.

Where should I keep this table at runtime? I have two approaches in mind: (1) is to put the entire table as a variable in the application delegate, in this case, I need to use objectForKey twice every time I need to get a string. (2) is to create a class with a static variable (not sure how to do it yet) and use class method to get the mapping e.g. +(NSString) stringForType: subType:

Could you please evaluate these two approaches or suggest better solutions? Thanks a lot!

4

1 回答 1

0

it doesn't really matter where you put it, as long as you keep exactly one copy of it, the important thing that you should check out is valueForKeyPath:. If you store in a plist, and save to the plist regularly you have the great benefit of persistence. You can get that automatically with the [NSUserDefaults standardUserDefaults]; object.

于 2011-05-25T05:19:47.287 回答