views:

64

answers:

1

Is there any common way to decompose an expression created by [NSPredicate predicateWithFormat] to objects NSComprasionPredicate, NSExpression and other?

For below example need to disassemble into components.

[NSPredicate predicateWithFormat:@"(0 != SUBQUERY(collection, $x, $x.name == "Name").@Count)"];
+1  A: 

+[NSPredicate predicateWithFormat:] is actually the front-end for a rather sophisticated parser. If you introspect the resulting NSPredicate, you'll find that it's not actually an NSPredicate, but either an NSComparisonPredicate or an NSCompoundPredicate.

Both of those types of predicates have lots of handy methods for convenient introspection.

In other words: NSPredicate is actually an "abstract" class. You'll usually only ever deal with comparison or compound predicates. There are other kinds, such as NSBlockPredicate, but they're all undocumented.

Dave DeLong
Sounds like a class cluster to me, like NSString and the Cocoa collections.
Quinn Taylor
I can imagine how to create predicate with predicateWithFormat. But I can not create predicate (in my question) using a set of objects such as NSExpression, NSComparisonPredicate, NSCompoundPredicate.
Victor