Re: Creating an NSExpression with a keypath and variable
Re: Creating an NSExpression with a keypath and variable
- Subject: Re: Creating an NSExpression with a keypath and variable
- From: Kyle Sluder <email@hidden>
- Date: Wed, 16 Mar 2011 11:34:36 -0700
On Wed, Mar 16, 2011 at 11:28 AM, Dave DeLong <email@hidden> wrote:
> Directly, yes. NSExpression stores a keypath as a single string, whereas variables are store in their own kind of NSExpression object. When you replace variables with new values, it's only looking for the certain kinds of NSExpression objects to replace. Everything else stays the same.
Well that's a shame. That's also probably why [[NSPredicate
predicateWithFormat:@"SUBQUERY(events, $x, $x = $someVar)"]
predicateWithSubstitutionVariables:[NSDictionary
dictionaryWithObject:@"foo" forKey:@"someVar"]] doesn't work, either.
It skips over the subquery NSExpression.
>
> Some notes about your predicate:
>
> - I'm not sure you can do "$x isKindOfClass: %@" as the predicate to a subquery, although I haven't tried it.
You can, but the syntax isn't documented. Then again, much of
NSPredicate is poorly documented.
> If it doesn't work, you could do this with a FUNCTION ("FUNCTION($x, 'ks_isKindOfClass:', %@)"). Note, however, that you'd have to create a category on NSObject that simply boxes the return value of isKindOfClass into an NSNumber. FUNCTION()'s don't like methods that return primitives.
It seems to deal with BOOLs just fine; I believe it's internally
wrapping the value in an NSNumber, much like how arbitrary keypaths
are supported on 10.5 and up (they get wrapped in NSNumbers or
NSValues if necessary).
--Kyle Sluder
_______________________________________________
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