On Fri, Jun 20, 2008 at 2:06 PM, Jesse Grosjean <[EMAIL PROTECTED]> wrote: >>> I want to construct searches such as: >>> >>> - find all entries that have a the tag named "priority" with the >>> value "1". > >> NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@"ANY >> tags.name = %@", tag.name]; >> NSPredicate *valuePredicate = [NSPredicate predicateWithFormat:@"ANY >> tags.value = %@", tag.value]; >> >> NSPredicate *combinedPredicate = [NSComparisonPredicate >> andPredicateWithSubpredicates:[NSArray arrayWithObjects:tagPredicate, >> valuePredicate,nil]]; > > Thanks, but I don't think this quite works. The problem is that the two ANY > predicates aren't forced to match against the same tag. So if the potential > matching entry has multiple tags this query will match if any of those tags > match the tag name, and if any of the tags values match the tag name, but > there's no constraint that a the same tag value pair matches both > constraints. > > Jesse >
You are correct, it doesn't work. And in trying to figure this out, I've come to realize that I've used predicates "the hard way" in some of my code. Try this instead: NSPredicate *pred = [NSPredicate predicateWithFormat:@"(SUBQUERY( tags, $x, $x.name = %@ AND $x.value = %@)[EMAIL PROTECTED] != 0)", @"aNameToMatch", @"aValueToMatch"]; Appears that this was a problem in 10.4 and fixed in 10.5. NSExpression's documentation for expressionForSubquery:usingIteratorVariable:predicate: has some discussion about it. -- Jim http://nukethemfromorbit.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]