Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

WillH16

macrumors newbie
Original poster
Apr 16, 2010
3
0
Hey all, so I'm creating this application where the user manipulates information that's stored in a dictionary. I want to be able to save these into NSUserDefaults and then retrieve them to display in a UITableView. Currently my code sets the dictionary to a key that's specific to the date that it is saved (i.e. Dictionary1 will be set with key "5-7-2010" in NSUserDefaults).

Is there a way for me to pull all these out and display them into a UITableView? I'd imagine I would create a NSMutableDictionary that will hold the dates as keys and the dictionaries as the values and then iterating through them to populate the table. Of course, this assumes that NSUserDefaults stores the objects as a sort-of dictionary, which at first glance seems to be true but I'm probably wrong.

Is this at all possible? Or was NSUserDefaults not meant to be utilized this way? I know I should probably use NSManagedObject and core data to do this, but I'm facing a deadline where I have to show at least some save functionality and I don't have enough time to read on it.

If my questions/descriptions are unclear please let me know and I will elaborate further and/or show some code. Thanks a bunch!
 
I'd imagine I would create a NSMutableDictionary that will hold the dates as keys and the dictionaries as the values and then iterating through them to populate the table.
How do you propose to iterate through the keys? Is their "range" known ahead of time? What about if you used an NSMutableArray instead?

Of course, this assumes that NSUserDefaults stores the objects as a sort-of dictionary, which at first glance seems to be true but I'm probably wrong.
No, you're correct. It's a "sort-of" dictionary.
 
How do you propose to iterate through the keys? Is their "range" known ahead of time? What about if you used an NSMutableArray instead?

It's not exactly difficult to get the keys as an array. If you are clever and store the dates as a string in YYYYMMDD format you can even sort them easily to get the table contents in order.

That said I'd probably save out to a plist in the apps documents rather than into NSUserDefaults...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.