Weird NSPredicate structure when using "first" in keypath
Weird NSPredicate structure when using "first" in keypath
- Subject: Weird NSPredicate structure when using "first" in keypath
- From: Jens Alfke <email@hidden>
- Date: Mon, 09 Jan 2017 18:01:34 -0800
I’m writing code that walks through an NSPredicate and generates an alternate form of query from it (similar to what CoreData and Realm do.)
I’m seeing some very weird undocumented behavior when format strings are compiled into NSPredicates, if the format string includes a key-path with a property named “first” or “last”. The resulting predicate contains an NSExpression of an undocumented type.
- For example, “name.middle == ‘Bob’” compiles to what you’d expect; the LHS of the ‘equals’ predicate is an expression of NSKeyPathExpressionType, with key-path “name.middle”.
- But “name.first == ‘Bob’” results in an LHS that’s of NSFunctionExpressionType, with a function selector “valueForKeyPath:”, and even weirder, the expression’s argument is an expression with the undocumented expressionType 11. I don’t know what that is supposed to mean, except that its -description is “FIRST” (all caps).
NSComparisonPredicate
predicateOperatorType = NSEqualToPredicateOperatorType
leftExpression =
NSKeyPathExpression
expressionType = NSFunctionExpressionType
function = “valueForKeyPath:”
operand =
NSKeyPathExpression
expressionType = NSKeyPathExpressionType
keyPath = “name”
operand = SELF
arguments = [
NSSymbolicExpression
expressionType = 11 (?????)
]
rightExpression =
NSExpression
expressionType = NSConstantValueExpressionType
constantValue = @“Bob”
Is there something magic about the property name “first”? The only related thing I’ve seen is that in predicate syntax arrays can be indexed with “[FIRST]” or “[LAST]”, but that’s in an array subscript not a keypath…
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden