I am trying to save an array of images in a documents folder. I managed to save the image as NSData and get it using the method below, but saving the array seems to be outside of me. I have considered several other issues that are related, and it seems that I'm doing everything right.
Adding an image as NSData and saving the image:
[imgsData addObject:UIImageJPEGRepresentation(img, 1.0)]; [imgsData writeToFile:dataFilePath atomically:YES];
Receiving data:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"imgs.dat"]; [self setDataFilePath:path]; NSFileManager *fileManager = [NSFileManager defaultManager]; if([fileManager fileExistsAtPath:dataFilePath]) imgsData = [[NSMutableArray alloc] initWithContentsOfFile:dataFilePath];
So, writing an image as NSData using the above works, but not an array of images as NSData. It takes an array, but has 0 objects, which is wrong, since the array that I save has several. Does anyone have any idea?
objective-c iphone
Beaker
source share