Create a new NSExpression

81 views Asked by At

How can i create a NSExpression with a constant value for using with the PredicateEditor.

for Example:

the leftExpression should be a string "state", the rightExpression should be as string "Germany"

i've tried:

NSExpression left = new NSExpression(NSExpressionType.ConstantValue);
left.SetValueForKey(new NSString("state"), new NSString("Germany"));

but this does not work. The Programm stops without error!

2

There are 2 answers

2
Marcos Vasconcelos On

You miss to throw the generated Exception with:

throw left;
0
Larry OBrien On

Use the static method NSExpression NSExpression.FromConstant(NSObject):

var left = NSExpression.FromConstant((NSString)"Germany");