Mar 142012
 

I didn’t write this code but it is too awesome not to share. I had an NSString and needed to see if it contained another NSString. I found this post: http://stackoverflow.com/questions/2753956/string-contains-string-in-objective-c

and P i‘s answer is just perfect; make a category on NSString:

@interface NSString ( containsCategory )
- (BOOL) containsString: (NSString*) substring;
@end

@implementation NSString ( containsCategory )

- (BOOL) containsString: (NSString*) substring
{    
    NSRange range = [self rangeOfString : substring];
    BOOL found = ( range.location != NSNotFound );
    return found;
}

@end

This has been incorporated into the open source EnkiUtils.