I have searched for the last several hours but have yet to find an answer. I implemented an AVFoundation camera, Im saving the image data to disk and storing only the path in core data. Everything works fine but after a random number of taken photos I get this error:
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[__NSDate localizedCaseInsensitiveCompare:]: unrecognized selector sent to instance
This is my fetch request code:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Photo"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"notebook = %@", notebookItem];
[request setPredicate:predicate];
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"dateTaken"
ascending:NO
selector:@selector(compare:)]];
And here is how I save the data in a separate class:
//I create a photo Object to save to core data and set properties like dateTaken and tittle
//Here is where I create the path name
NSDate *dateString = [[NSDate alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
NSString *path = [formatter stringFromDate:dateString];
//Now I save to disk
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// the path to write file
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:path];
NSLog(@"path: %@", path);
[[[self captureManager] ImageDataObject] writeToFile:filePath atomically:YES];
photo.imagePath = filePath;
[notebookItem addPhotosObject:photo];
[self.SharedDocumentHandlerInstance saveDocument];
I tracked down the point of crash and it occurs in the line of code where I save the document (the last one above) but maybe the fetch request is the one that causes it. I also set self.fetchedResultsController.delegate = nil in my table. And again, this error occurs after a random number of photos is taken. Thanks for any help in advance!