re: [Leopard] SUBQUERY predicate with CoreData
re: [Leopard] SUBQUERY predicate with CoreData
- Subject: re: [Leopard] SUBQUERY predicate with CoreData
- From: Ben Trumbull <email@hidden>
- Date: Mon, 4 Feb 2008 15:29:08 -0800
[fetch setPredicate:[NSPredicate
predicateWithFormat:@"(SUBQUERY(self.keyValues, $kv, $kv.key like
'key1' && $kv.floatValue==1.0).count > 0) && fooProp like
'fooProp1'"]];
A SUBQUERY expression produces an array of results, a lot like
NSArray's -filteredArrayWithPredicate:
Tacking on .count at the end is adding a keypath. Basically it's like
[subqueryResults valueForKeyPath:@"count"]
NSArray responds to the keypath .count by invoking -count on each
element and giving you back an array of all the counts. This array
is not happy being compared to a scalar 0.
NSArray responds to the keypath "@count" in the manner you want. You
can use either
"(SUBQUERY(self.keyValues, $kv, $kv.key like 'key1' &&
$kv.floatValue==1.0).@count > 0)"
or
"(SUBQUERY(self.keyValues, $kv, $kv.key like 'key1' &&
$kv.floatValue==1.0)[size] > 0)"
where the second form is using some of the built-in predicate
operators for aggregates.
--
-Ben
_______________________________________________
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