NSComparisonPredicate NSDiacriticInsensitivePredicateOption
These constants describe the possible types of string comparison for NSComparisonPredicate. These options are supported for LIKE as well as all of the equality/comparison operators.
enum {
NSCaseInsensitivePredicateOption = 0x01,
NSDiacriticInsensitivePredicateOption = 0x02,
NSNormalizedPredicateOption = 0x04,
NSLocaleSensitivePredicateOption = 0x08
};
typedef NSUInteger NSComparisonPredicateOptions;
Constants
NSCaseInsensitivePredicateOption
A case-insensitive predicate.
You represent this option in a predicate format string using a [c] following a string operation (for example, "NeXT" like[c] "next").
NSDiacriticInsensitivePredicateOption
A diacritic-insensitive predicate.
You represent this option in a predicate format string using a [d] following a string operation (for example, "naïve" like[d] "naive").
NSNormalizedPredicateOption
Indicates that the strings to be compared have been preprocessed.
This option supersedes NSCaseInsensitivePredicateOption and NSDiacriticInsensitivePredicateOption, and is intended as a performance optimization option.
You represent this option in a predicate format string using a [n] following a string operation (for example, "WXYZlan" matches[n] ".lan").
NSLocaleSensitivePredicateOption
Indicates that strings to be compared using <, <=, =, =>, > should be handled in a locale-aware fashion.
You represent this option in a predicate format string using a [l] following one of the <, <=, =, =>, > operators (for example, "straße" >[l] "strasse").
NSComparisonPredicate NSDiacriticInsensitivePredicateOption example.
NSExpression * leftExpression = [NSExpression expressionForKeyPath:@"name"];
NSExpression * rightExpression = [NSExpression expressionForConstantValue:@"Hello!"];
NSComparisonPredicate * predicate = [NSComparisonPredicate predicateWithLeftExpression:leftExpression
rightExpression:rightExpression
modifier:NSDirectPredicateModifier
type:NSContainsPredicateOperatorType
options:(NSCaseInsensitivePredicateOption | NSDiacriticInsensitivePredicateOption)];
NSExpression * rightExpression = [NSExpression expressionForConstantValue:@"Hello!"];
NSComparisonPredicate * predicate = [NSComparisonPredicate predicateWithLeftExpression:leftExpression
rightExpression:rightExpression
modifier:NSDirectPredicateModifier
type:NSContainsPredicateOperatorType
options:(NSCaseInsensitivePredicateOption | NSDiacriticInsensitivePredicateOption)];
Example of [NSComparisonPredicate NSDiacriticInsensitivePredicateOption].
NSPredicate *nameQuery =
[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"s_name"]
rightExpression:[NSExpression expressionForConstantValue:Name]
modifier:NSDirectPredicateModifier
type:NSLikePredicateOperatorType
options:NSCaseInsensitivePredicateOption|NSDiacriticInsensitivePredicateOption];
NSPredicate *regNoQuery =
[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"s_regno"]
rightExpression:[NSExpression expressionForConstantValue:RegNo]
modifier:NSDirectPredicateModifier
type:NSEqualToPredicateOperatorType
options:0];
NSPredicate *query = [NSCompoundPredicate andPredicateWithSubpredicates:@[nameQuery,regNoQuery]];
[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"s_name"]
rightExpression:[NSExpression expressionForConstantValue:Name]
modifier:NSDirectPredicateModifier
type:NSLikePredicateOperatorType
options:NSCaseInsensitivePredicateOption|NSDiacriticInsensitivePredicateOption];
NSPredicate *regNoQuery =
[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"s_regno"]
rightExpression:[NSExpression expressionForConstantValue:RegNo]
modifier:NSDirectPredicateModifier
type:NSEqualToPredicateOperatorType
options:0];
NSPredicate *query = [NSCompoundPredicate andPredicateWithSubpredicates:@[nameQuery,regNoQuery]];