• 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: Core Data: case insensitive "equals" predicate strings!?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data: case insensitive "equals" predicate strings!?


  • Subject: Re: Core Data: case insensitive "equals" predicate strings!?
  • From: Frank Reiff <email@hidden>
  • Date: Tue, 8 Jan 2008 17:03:01 +0100

Hi Ken,

Thanks. You're of course right: my construction is not even safe; the A contains B and B contains A would better.

I naturally do look through the documentation before asking silly questions on this group, but there simply does not seem to exist any way of performing a case insensitive "equals" using the predicate string format. After having googled my way through the usual places of wisdom (CocoaDev, CocoaBuilder, etc.), I came up empty except for the very same question having been asked before, but not answered..

For the permanent record then, the code below seems to work:

NSPredicate* predicate = [NSComparisonPredicate predicateWithLeftExpression: [NSExpression expressionForKeyPath: @"fullDestinationPath"]
rightExpression: [NSExpression expressionForConstantValue: newFullPath]
modifier: NSDirectPredicateModifier type: NSEqualToPredicateOperatorType options: NSCaseInsensitivePredicateOption];


Since there does not appear to be any way of expressing this as a predicate string, I will log a bug report with Apple asking them to add ==[c] or ==[cd] or something similar to the formatting string syntax.

Best regards,

Frank

On 7 Jan 2008, at 23:22, Ken Thomases wrote:

On Jan 7, 2008, at 2:29 PM, Frank Reiff wrote:

I've had to resort to the very lame:

NSPredicate* predicate = [NSPredicate predicateWithFormat: @"%K BEGINSWITH[c] %@ AND %K ENDSWITH[c] %@", @"fullDestinationPath", newFullPath];

to get things to work properly.. surely this is not the recommended way of doing case insensitive matching for core data?

I don't see an obvious case-insensitive equals operator. LIKE or MATCHES are tempting, but get you in trouble if either of the arguments include characters that are interpreted as meta-characters.


However, I would not use the BEGINSWITH AND ENDSWITH construction that you're using. That would match if fullDestinationPath happened to contain the concatenation of newFullPath with itself.

I think that something like A CONTAINS[c] B AND B CONTAINS[c] A would be safer.

Still, you're right, it's far from elegant.

-Ken

_______________________________________________

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: Core Data: case insensitive "equals" predicate strings!?
      • From: mmalc crawford <email@hidden>
References: 
 >Core Data: case insensitive "equals" predicate strings!? (From: Frank Reiff <email@hidden>)
 >Re: Core Data: case insensitive "equals" predicate strings!? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Error executing instruction "[NSBezierPath bezierPath]"
  • Next by Date: Re: Debugging a NibLoad binding error
  • Previous by thread: Re: Core Data: case insensitive "equals" predicate strings!?
  • Next by thread: Re: Core Data: case insensitive "equals" predicate strings!?
  • Index(es):
    • Date
    • Thread