Skip to content

Instantly share code, notes, and snippets.

@defragged
Last active November 24, 2016 07:48
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save defragged/cd1649edbf7934a37e17 to your computer and use it in GitHub Desktop.
Save defragged/cd1649edbf7934a37e17 to your computer and use it in GitHub Desktop.
Method to do case insensitive string comparisons, working around the method returning `YES` if the receiver is `nil`.
#import <Foundation/Foundation.h>
/** Methods to help with determining string equality */
@interface NSString (Equality)
/**
* Returns `YES` if the receiving string is equal to the
* argument, ignoring case.
*
* So `latex` will be equal to `LaTeX` for instance.
*
* @param string The string to compare with
* @return `YES` if the strings are equal. `NO` otherwise.
*/
- (BOOL)isEqualIgnoringCase:(NSString *)string;
@end
#import "NSString+Equality.h"
@implementation NSString (Equality)
- (BOOL)isEqualIgnoringCase:(NSString *)string {
return [self caseInsensitiveCompare:string] == NSOrderedSame;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment