Skip to content

Instantly share code, notes, and snippets.

@ryanmaxwell
Last active December 14, 2015 22:28
Show Gist options
  • Save ryanmaxwell/5158157 to your computer and use it in GitHub Desktop.
Save ryanmaxwell/5158157 to your computer and use it in GitHub Desktop.
NSString+Comparisons
@interface NSString (Comparisons)
- (BOOL)containsString:(NSString *)substring;
- (BOOL)isSubstringOfString:(NSString *)string;
- (BOOL)isEqualToAnyOfStrings:(NSArray *)strings;
- (BOOL)isEqualToNoneOfStrings:(NSArray *)strings;
@end
#import "NSString+Comparisons.h"
@implementation NSString (Comparisons)
- (BOOL)containsString:(NSString *)substring {
NSRange range = [self rangeOfString:substring];
return (range.location != NSNotFound);
}
- (BOOL)isSubstringOfString:(NSString *)string {
NSRange range = [string rangeOfString:self];
return (range.location != NSNotFound);
}
- (BOOL)isEqualToAnyOfStrings:(NSArray *)strings {
for (NSString *string in strings) {
if ([self isEqual:string]) return YES;
}
return NO;
}
- (BOOL)isEqualToNoneOfStrings:(NSArray *)strings {
for (NSString *string in strings) {
if ([self isEqual:string]) return NO;
}
return YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment