• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
re: [Leopard] SUBQUERY predicate with CoreData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: NSTextView/text system slowdown on Leopard
  • Next by Date: sendSynchronousRequest and didReceiveAuthenticationChallenge
  • Previous by thread: Re: [Leopard] SUBQUERY predicate with CoreData
  • Next by thread: Re: [Leopard] SUBQUERY predicate with CoreData
  • Index(es):
    • Date
    • Thread