0

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!

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
Klaus Grosche
  • 85
  • 1
  • 7

2 Answers2

1

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

var left = NSExpression.FromConstant((NSString)"Germany");
Larry OBrien
  • 8,484
  • 1
  • 41
  • 75
0

You miss to throw the generated Exception with:

throw left;
Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • the programm stop while left.SetValueForKey. So i can not do throw left; – Klaus Grosche Nov 06 '17 at 14:09
  • OK, i don't want to throw left, i would like to create an NSExpression for the leftExpression of a NSPredicate.Subpredicates[].LeftExpression. I was looking for several hours but i did not find the right way. – Klaus Grosche Nov 06 '17 at 18:23