I want to save the images in NSLibraryDirectory, the code i am using is replacing image, when next image is saved.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"images.doc"];
UIImage *image = [arrayImages objectAtIndex:0];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
Each time you have to use a different name that isn’t already used.So You have to change the file name Each time.
If you want work it even after app restarted ,Save the index value to NSUserDefaults
.h file
Change your code as in .m