• 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: "Barry Wark" <email@hidden>
  • Date: Mon, 4 Feb 2008 17:00:21 -0800

Thank you to Ben and Melissa for setting me straight. I notice that
the NSExpression documentation gives

"SUBQUERY(residents, $x, $x.firstname == "Jane" && $x.lastname ==
"Doe").count != 0)"

as an example subquery for a similar use case. Besides the missing
opening '(', this example has the, as I know now, incorrect use of
.count != 0 pattern. Is this well known, or worth filing a bug for the
documentation?

Thanks,
Barry

On Feb 4, 2008 3:29 PM, Ben Trumbull <email@hidden> wrote:
> >[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

  • Follow-Ups:
    • Re: [Leopard] SUBQUERY predicate with CoreData
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: Login item support for Panther, Tiger and Leopard
  • Next by Date: Re: [Leopard] SUBQUERY predicate with CoreData
  • Previous by thread: re: [Leopard] SUBQUERY predicate with CoreData
  • Next by thread: Re: [Leopard] SUBQUERY predicate with CoreData
  • Index(es):
    • Date
    • Thread