Re: Predicate variable substitution
Re: Predicate variable substitution
- Subject: Re: Predicate variable substitution
- From: Mark Slater <email@hidden>
- Date: Sat, 29 Oct 2005 12:51:21 -0700
Thank you... that made it work for the NSPredicate substitution.
Unfortunately, XCode doesn't seem to allow non-String Literals in the
fetch requests. I've selected "name" from the attribute list, "LIKE"
from the operation list, and entered "$THE_NAME" (without quotes) in
the text field, and XCode comes up with a predicate that has quotes
around the text. Is this simply a known limitation for XCode's
predicate editing?
Mark
On Oct 29, 2005, at 10:35 AM, Mark Slater wrote:
[ NSPredicate predicateWithFormat: @"name like '$THE_NAME'" ];
@"name like $THE_NAME"
By adding quotes around the variable name, you're making it a
string literal.
<http://developer.apple.com/documentation/Cocoa/Conceptual/
Predicates/ Articles/pCreating.html#//apple_ref/doc/uid/
TP40001793-219639-BCIIHDCH>
mmalc
On Oct 29, 2005, at 10:35 AM, Mark Slater wrote:
I'm trying to write a fetch request in XCode that will load all
objects with a specified name value. As in, the type has an
attribute "name" and I want to fetch based on that attribute. The
problem I'm having is that I can't get any fetch request using
substitution to work. Here's my code:
// Now try to use the fetch request saved in XCode.
NSFetchRequest *fetchByNameRequest = [ mom
fetchRequestFromTemplateWithName: @"fetchDescriptionByName"
substitutionVariables: [ NSDictionary
dictionaryWithObject: DEFAULT_NAME forKey:
@"THE_NAME" ] ];
NSLog( @"fetchByNameRequest = %@", fetchByNameRequest );
NSArray *results = [ context executeFetchRequest:
fetchByNameRequest error: &error ];
NSLog( @"fetchByNameRequest found objects: %@", results );
NSLog( @"error = %@", error );
My problem is that predicate substitution for variables doesn't
seem to work, nor does the XCode substitution using
fetchRequestFromTemplateWithName:substitutionVariables:. The
predicate for fetchDescriptionByName in XCode reads:
name LIKE "$LIB_NAME"
There are a few things that come to mind which could be affecting
this. This function is being called from the Application
Delegate's applicationWillFinishLaunching: method, so maybe some
things are ready to be called at this point? Also, in my data
model I've got an abstract "Description" entity, and two concrete
sub-entities "StaticDescription" and "DynamicDescription". The
fetch request is defined on the abstract "Description" class
because I'd like to get all Descriptions, regardless of their
exact sub-type, but in this case, I know the type I'm looking for
is a "StaticDescription". The hand coded fetch request works with
both the abstract and concrete entities.
If anyone has some insight into why the NSPredicate substitution
isn't working for me, or why the XCode fetch template doesn't work
when a hand coded NSFetchRequest does, I'd appreciate your help.
Thanks!
Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden