0

I have a CoreData model that looks a bit like this:

Object A:
  Results -- A one to many relationship to an indeterminate number of Object B's.

Object B:
  Object Name -- A string.  (potentially not unique)
  Parent -- A singular relationship with Object A.

I am struggling with writing a NSPredicate that will return ObjectB if I know a given Object A and the Object Name string I am looking for. I have tried the following, but always get this error:

"'NSInvalidArgumentException', reason: 'Unable to parse the format string ..."

request.predicate = [NSPredicate predicateWithFormat:@"NameString == %@, SELF IN %@", NameString, ObjectA.results];

request.predicate = [NSPredicate predicateWithFormat:@"(NameString == %@) IN %@", NameString, ObjectA.results];

And so on...

This seems like this should be a simple and obvious thing to do, but I am new at Core Data and am having trouble finding an example that shows this.

Thanks!

radven
  • 2,296
  • 1
  • 22
  • 39

1 Answers1

0

You need to use %K.

You may need something like this in your predicate

 NSString enitity=@"ObjectA";
 NSString attribute=@"results";
 request.predicate = [NSPredicate predicateWithFormat:@"NameString == %@, SELF IN %K.%K", NameString, enitity,attributes];

Look here.

Will Johnston
  • 864
  • 4
  • 18