Can I use a keyPath in a predicate?
Posted
by dontWatchMyProfile
on Stack Overflow
See other posts from Stack Overflow
or by dontWatchMyProfile
Published on 2010-06-17T18:59:13Z
Indexed on
2010/06/17
19:03 UTC
Read the original article
Hit count: 290
For some reason, this didn't work (although the keypath does exist):
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"department.departmentName == %@", departmentName];
[fetchRequest setPredicate:predicate];
NSError *fetchError = nil;
NSUInteger count = [moc countForFetchRequest:fetchRequest error:&fetchError]; // execution simply stops at this line, with no error or console log
Execution just stops at the last line above when asking for the count. I don't get an console log. Also I don't get any kind of exception. The execution just stops. There are no objects in the persistent store yet. So maybe it crashes because of it tries to follow a keypath in a nonexisting object? Does that make sense?
The line where GDB stops is this:
0x002a31cb <+0459> test %eax,%eax
Previously to that, I see a lot of NSSQLAdapter... calls in the stack trace. There's definitely something wrong.
Well, but when I set the Entity to the destination of the key path and then just do something like
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"departmentName == %@", departmentName];
then there is no problem and count simply is 0.
© Stack Overflow or respective owner