次のように使用しNSPredicate
てください:
NSString *strFormula1 = @"\"man\" == \"man\" && 1<5 || 12<9";
NSString *strFormula2 = @"\"pac@pac.com\" == \"pac1@pac1.com\" || 9==9 && 8>2 || 2==2";
NSString *strFormula3 = @"\"hello\" == \"world\"";
NSPredicate *predicate = [NSPredicate predicateWithFormat:strFormula1];
BOOL result = [predicate evaluateWithObject:nil]; //True
predicate = [NSPredicate predicateWithFormat:strFormula2];
result = [predicate evaluateWithObject:nil]; //True
predicate = [NSPredicate predicateWithFormat:strFormula3];
result = [predicate evaluateWithObject:nil]; //False
そして、述語が式をどのように解析したかを知りたい場合は、次を使用してください。
NSLog(@"%@", [predicate predicateFormat]);
私たちの場合、これは次を返します:
("man" == "man" AND 1 < 5) OR 12 < 9 //1st Expression
"pac@pac.com" == "pac1@pac1.com" OR (9 == 9 AND 8 > 2) OR 2 == 2 //2nd Expression
"hello" == "world" //3rd Expression