Created
January 28, 2013 18:37
-
-
Save akrabat/4657932 to your computer and use it in GitHub Desktop.
Simple (No doubt, inefficient) word count system in Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSUInteger) wordCount: (NSString *) string { | |
__block NSUInteger wordCount = 0; | |
[string enumerateSubstringsInRange:NSMakeRange(0, string.length) | |
options:NSStringEnumerationByWords | |
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
wordCount++; | |
}]; | |
return wordCount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment