1

I'm using the code below with my NSFetchedResultController

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.objRelationship.ObjectId == %@", objectFromOtherContext.ObjectId];
[fetchRequest setPredicate:predicate];

The NSManagedObjectContext being use by NSFetchedResultController is different from the NSManagedObjectContext of objectFromOtherContext variable. The NSFetchedResultController does not return any data. However, it is returning something if they are using the same NSManagedObjectContext.

Is there a way to filter by ObjectId if the NSManagedObjectContext of the NSFetchedResultController is different from the NSManagedObjectContext of the NSManagedObject that was passed to the predicate? (assuming the object is already saved on the persistent store).

tkanzakic
  • 5,499
  • 16
  • 34
  • 41
apisip
  • 333
  • 1
  • 4
  • 10

1 Answers1

0

I came across this problem today. You cannot use an object in a predicate that was created in a different context, you can't even use it's objectID. You'll need to query for the object first in the same context you want to search. Alternatively you could try doing [newContext objectWithID:objectFromOtherContext.ObjectId] and then using that in your predicate.

malhal
  • 26,330
  • 7
  • 115
  • 133