开发者

Objective C, How to store data in NSMutable Array

开发者 https://www.devze.com 2023-02-15 05:25 出处:网络
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 i

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.开发者_StackOverflow社区 What is the best way for this?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号