I am trying to store many images in NSDocument with the name pattern like :-
image 1, image 2, image 3, image 4, .....
Image count should increase with number of times a register button is tapped. And for storing this button tapped count i am using NSUserDefault. But the problem is that i am only able to store 1 image after that the application is crashing.
Following is the code i am using :-
- (IBAction)registerFaceAction:(id)sender
{
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
long count = [userDefaults integerForKey:@"my_key"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:count];
NSMutableString *imageName = [NSMutableString string];
[imageName appendString:[NSString stringWithFormat:@"ImageData %ld", count]];
[imageName appendString:[NSString stringWithFormat: @".png"]];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:imageName];
UIImage *image = _inputImage;
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
[userDefaults setInteger:count+1 forKey:@"my_key"];
[userDefaults synchronize];
}