views:

191

answers:

3

I have an NSMutableArray that holds multiple and changing amounts (that's why I am using an NSMutableArray) of UIImageView's that I want to save and also in return load when my app quits and loads. Also, how would I then, after my app loads, get the image viws out of the array

A: 

You should consult the Core Data Programming Guide and follow the tutorials there. It will teach you how to serialize and deserialize data structures and views.

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html

Tomen
a simpler version to achieve your goal could be to use archieving: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/Archiving/Archiving.html
Tomen
A: 

Core Data might be overkill. Id just use archive the mutable array like Tomen said.

Note that UIImageView (and the rest of the views, I believe) don't really support serialization from my experience. They only claim to support the NSCoding protocol because initWithCoder is used with loading NIB files. I wouldn't try to save the whole view, I'd only save the images. You'll probably need to retrieve the UIImage from the UIImageView, then get the CGImage from that, then get the NSData object for the bitmap from that. Also:

Because image objects are immutable, they also do not provide direct access to their underlying image data. However, you can get an NSData object containing either a PNG or JPEG representation of the image data using the UIImagePNGRepresentation and UIImageJPEGRepresentation functions.

To archive the NSMutableArray the items in the array need to support encodeWithCoder (Which NSData does) so you may just want to build a new array with the NSData objects.

Nimrod
A: 

Hi,

I am also having the same issue. Can you please post the sample code if you found a solution for this.

Thanks, XYZ.