Skip navigation.
 
mlRe: Core Data: case insensitive "equals" predicate strings!?
FROM : Frank Reiff
DATE : Tue Jan 08 17:03:01 2008

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

Related mailsAuthorDate
mlCore Data: case insensitive "equals" predicate strings!? Frank Reiff Jan 7, 21:29
mlRe: Core Data: case insensitive "equals" predicate strings!? mmalc crawford Jan 7, 23:01
mlRe: Core Data: case insensitive "equals" predicate strings!? Ken Thomases Jan 7, 23:22
mlRe: Core Data: case insensitive "equals" predicate strings!? Frank Reiff Jan 8, 17:03
mlRe: Core Data: case insensitive "equals" predicate strings!? mmalc crawford Jan 8, 17:33
mlRe: Core Data: case insensitive "equals" predicate strings!? Ken Thomases Jan 9, 01:22
mlRe: Core Data: case insensitive "equals" predicate strings!? mmalc crawford Jan 9, 02:53
mlRe: Core Data: case insensitive "equals" predicate strings!? Ken Thomases Jan 11, 01:55
mlRe: Core Data: case insensitive "equals" predicate strings!? slasktrattenator Jan 11, 11:46
mlRe: Core Data: case insensitive "equals" predicate strings!? Frank Reiff Jan 11, 17:22