1

I have a class has 4 NSString variables and 1 UIImage variable. Also I have NSMutable Array that holding several instances of the class. I want to store the data in NSMutalbe array into somewhere in iPhone. What is the best way for this?

codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167
  • 1
    Seems like you're looking for Core Data. It's basically cocoa's serialization/deserialization mechanism. http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreData/cdProgrammingGuide.html – Ben Mar 06 '11 at 00:06

2 Answers2

1

You can use NSUserDefaults to store some data: iPhone - how to save user settings from application? or try any other kind of persistent storage: iPhone Persistent Storage

Community
  • 1
  • 1
Jonas Bötel
  • 4,452
  • 1
  • 19
  • 28
  • Thanks for the quick response. It seems like this works only if I want to store a few variables. In my case, the mutable array will have at least 30 instances of the class that has 4 NSString variables and 1 UIImage variable. So it this method still ok with this situation ? One way I can think of was that I might create an XML file and store that in somewhere in iPhone and when application launches I read the XML file and parse it and populate the array again... Is this way a good approach? – codereviewanskquestions Mar 06 '11 at 01:12
0

Basically, if the data is fairly small (but the uiimages make it seem not small), then you can store it in the prefs. You can't store the array of custom objects, you have to make an nsarray of nsdictionaries, and store that.

If there is more data you should store in a file in the documents folder.

The UIImages - store as PNGs - there is a call to get an image as NSData, then you would have an nsarray of nsdictionaries, and a routine for creating the dict, and one for reading it and making up instances of your classes.

If the images are really large, you are going to want to store the images as files by themselves, and just put the path into the dictionary that you store.

Tom Andersen
  • 7,132
  • 3
  • 38
  • 55