Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.