I am getting this weird exception and I have no clue how to figure out what’s going wrong here
"Serious application error. **Exception was caught during Core Data change processing.** This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. **Can't look for value (552284302) in string (1070635162, 630076961, 690758344, 714304224, 693603903, 650263092, 552284302); value is not a string with userInfo (null)**"
My code is as follows:
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSManagedObjectContext *context = [ (MyAppDelegate*)[[UIApplication sharedApplication] delegate]managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"MyEntityName" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"distance" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
User *user = [[DatabaseHelper sharedInstance] getUserDetails];
NSString *predicteString = [NSString stringWithFormat:@"isPrivate == %@ AND recepientList contains %@", [NSNumber numberWithBool:YES], user.userId];
if(dootType == UnReadDootType){
predicteString = [predicteString stringByAppendingString:@" AND state = 'NEW' "];
}
NSPredicate *predicate;
if(senderId != nil && [senderId intValue] > 0){
predicteString = [predicteString stringByAppendingString:@" AND senderId == %@"];
predicate = [NSPredicate
predicateWithFormat:predicteString, senderId];
}else{
predicate = [NSPredicate
predicateWithFormat:predicteString];
}
[fetchRequest setPredicate:predicate];
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:context sectionNameKeyPath:nil
cacheName:@"MyEntityName"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
[sort release];
[fetchRequest release];
[theFetchedResultsController release];
return _fetchedResultsController;
}
The NSFetchRequest logs as:
<NSFetchRequest: 0x362350> (entity: MyEntityName; predicate: (isPrivate == 1 AND recepientList CONTAINS 552284302); sortDescriptors: ((
"(distance, ascending, compare:)"
)); batch size: 20; type: NSManagedObjectResultType; )
So as you can see I am using a predicate like recepientList CONTAINS 552284302
and for one of my record the recepientList has 1070635162, 630076961, 690758344, 714304224, 693603903, 650263092, 552284302 I am storing comma separated userId in the recepientList, so I am not sure why this exception.
The
user.userIDis being parsed as a numerical value instead of a string. TheCONTAINSoperator does not understand numerical values.The predicate that logs as:
… should log as:
The former predicate looks for a numerical value while later looks for a string. (Note that the numerical one in
isPrivate == 1is not quoted.)If
user.userIDis a NSNumber then getting it’s string value should correct the problem. Try: