Skip navigation.
 
mlCore Data: case insensitive "equals" predicate strings!?
FROM : Frank Reiff
DATE : Mon Jan 07 21:29:40 2008

Dear group,

Sorry, but this is yet another lame Core Data question: when using a 
predicate string to perform a fetch, e.g.

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

The equals (==) is case insensitive; I need a case sensitive equals. 
The operations supported on strings all take modifiers, so you can 
write:

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

where the [c] part means "case insensitive". Works like a charm, but 
there's no equals operation specifically for strings.. the obvious 
solution:

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

throws an invalid argument exception.

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?

The "newFullPath" variable obviously is a string that may contain any 
number of special characters so wild-card matching is out. What's more 
this is a probably the most performance critical part of the program..

Any thoughts?

Best regards,

Frank

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