caseInsensitiveCompare:
Returns the result of invoking
compare:options:
with NSCaseInsensitiveSearch
as the only option.
- (NSComparisonResult)caseInsensitiveCompare:(NSString *)aString
Parameters
- aString
- The string with which to compare the receiver.This value must not be
nil
. If this value isnil
, the behavior is undefined and may change in future versions of OS X.
Return Value of [NSString caseInsensitiveCompare]
The result of invoking
compare:options:
with NSCaseInsensitiveSearch
as the only option.Discussion of [NSString caseInsensitiveCompare]
If you are comparing strings to present to the end-user, you should typically use
localizedCaseInsensitiveCompare:
instead.
Example of [NSString caseInsensitiveCompare]
NSString *rank = [[NSUserDefaults standardUserDefaults] stringForKey:@"Rank"];
if ([rank caseInsensitiveCompare:@"MANAGER"] == NSOrderedSame) {
// what happens if "Rank" is not found in standardUserDefaults
}
Example of [NSString caseInsensitiveCompare]
NSArray *sortedValues = [[yourDictionary allValues] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSMutableDictionary *orderedDictionary=[[NSMutableDictionary alloc]init];
for(NSString *valor in sortedValues){
for(NSString *clave in [yourDictionary allKeys]){
if ([valor isEqualToString:[yourDictionary valueForKey:clave]]) {
[orderedDictionary setValue:valor forKey:clave];
}
}
}
Example of [NSString caseInsensitiveCompare]
NSArray *keys = [dict allKeys];
NSArray *sKeys = [keys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSMutableArray *sValues = [[[NSMutableArray alloc] init] autorelease];
for(id k in sKeys) {
id val = [dict objectForKey:k];
[sValues addObject:val];
}