NSFetchedResultsController Table Table always stops working with SECOND object insertion

I am using NSFetchedResultsController to control the display of selected managed objects in a table in which there is one section. The table starts empty, and the user can add new objects to it using the user interface. Be that as it may, the program always works when adding the first object and always resets when adding the second. Sometimes there are no errors that occur during a failure, and sometimes errors of different types occur (some of which are given below). Through the log and tracing instructions, I see that the program crashes right after the NSFetchResultsController delegates the WillChangeContent controller (which calls the [self.tableView beginUpdates]; method), but before calling any other method in my code. Here are some parts of my code. Configure NSFetchedResultsController:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Beer"
                                    inManagedObjectContext:self.managedObjectContext]];

// Configure request entity and predicate
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];

NSString *expression = [NSString stringWithFormat:@"brewery.name LIKE \"%@\"", self.brewery.name];
NSPredicate *predicate = [NSPredicate predicateWithFormat:expression];
[fetchRequest setPredicate:predicate];
self.resultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                                             managedObjectContext:self.managedObjectContext
                                                               sectionNameKeyPath:nil
                                                                        cacheName:nil];
self.resultsController.delegate = self;
[fetchRequest release];

NSError *error = nil;
BOOL success = [resultsController performFetch:&error];
if (!success) {
    NSLog(@"Error fetching request %@", [error localizedDescription]);
}

:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Beer" inManagedObjectContext:self.managedObjectContext];
Beer *beer = [[Beer alloc] initWithEntity:entity insertIntoManagedObjectContext:self.managedObjectContext];
beer.name = beerName;
beer.brewery = self.brewery;

, Apple . .

, :

Serious application error.  Exception was caught during Core Data change processing: *** -[NSCFString compareObject:toObject:]: unrecognized selector sent to instance 0x4e808c0 with userInfo (null)
Serious application error.  Exception was caught during Core Data change processing: *** -[CALayer compareObject:toObject:]: unrecognized selector sent to instance 0x4e53b80 with userInfo (null)
Serious application error.  Exception was caught during Core Data change processing: *** -[UITextTapRecognizer controllerWillChangeContent:]: unrecognized selector sent to instance 0x4ca5d70 with userInfo (null)
Serious application error.  Exception was caught during Core Data change processing: *** -[CALayer controllerWillChangeContent:]: unrecognized selector sent to instance 0x4e271a0 with userInfo (null)
Serious application error.  Exception was caught during Core Data change processing: *** -[NSCFNumber countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x4c96ee0 with userInfo (null)

, ( ) , .

- , ?

+5
5

. , . , , , , , .

:

  • NSZombie
  • objc_exception_throw

, , . , . , , NSFetchedResultsController, , - .

.

+4

. :

Beer* beer = [NSEntityDescription insertNewObjectForEntityForName: @"Beer" 
    inManagedObjectContext: self.managedObjectContext];
beer.name = @"Grolsch";

, NSManagedObjectContext#save:. , , ?

+1

, , , . NSFetchedResultsController, , , controllerDidChangeContent:, [tableView reloadData].

, RootViewController, XCode, . , , .

+1

- , :

[sortDescriptors release];

sortDescriptors

[NSArray arrayWithObjects:sortDescriptor, nil];

"alloc", "copy" "new", . , , - NSFetchRequest , . . Apple .

+1

, , , , , , , , , .

, compareObject: toObject, .

- [_ NSCFSet compareObject: toObject:]: unrecognized selector sent to the instance - [_ NSCFString compareObject: toObject:] unrecognized selector sent to the instance

My suggestion is to try to eliminate all sort descriptors and predicates from your code, and then add them one by one to find where the problem is.

Good luck Horn

0
source

All Articles