I don't think it's possible without a format string.  

"$x.firstName" gets turned into an expression of type NSFunctionExpression.  
The operator is a variable expression, and the first argument is an expression 
with a private type (10).  gdb shows that the class of that argument is 
"NSKeyPathSpecifierExpression", but there doesn't appear to be a way to create 
one programmatically without a format string.

Similarly, the SUBQUERY(...).@count gets turned into a FUNCTION() expression.  
The operand is the subquery expression, and the first argument is another 
expression of type 10.

I think you're out of luck and will have to build a format string and pass that 
to predicateWithFormat:.  I'd probably file a bug requesting more API if I were 
you.

HTH,

Dave

On Sep 26, 2011, at 7:05 AM, Willeke wrote:

> hi,
> 
> How do I programmatically create the $x.firstname and .@count parts of this 
> expression?
> SUBQUERY(residents, $x, $x.firstname == "Jane" && $x.lastname == "Doe").@count
> 
> When I create a subquery predicate with predicateWithFormat:, the class of 
> the $x.firstname and .@count expressions is NSKeyPathExpression and the type 
> is NSFunctionExpressionType. The operand is an expression of type 
> NSVariableExpressionType or NSSubqueryExpressionType. The function is 
> valueForKeyPath:.
> 
> When I create an expression with expressionForKeyPath:, the operand is SELF 
> instead of the variable or the subquery. When I create an expression with 
> expressionForFunction:selectorName:arguments:, the class is 
> NSFunctionExpression. When the argument is a keypath expression, instead of 
> $x.firstname the expression tries to evaluate $x.Jane and that doesn't work. 
> executeFetchRequest throws an exception: -constantValue only defined for 
> abstract class.  Define -[NSKeyPathExpression constantValue]!
> If the argument is a constant value expression, executeFetchRequest throws an 
> exception: -keyPath only defined for abstract class.  Define 
> -[NSConstantValueExpression keyPath]!.
> 
> The predicate will be edited in a rule editor so I have to convert it to 
> criteria and back.
> The predicate will be used as filter predicate of an array controller in 
> entity mode and/or in a fetch request with Core Data (SQLite).
> 
> Thanks,
> Willeke
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to