Created
May 10, 2015 15:39
-
-
Save daehn/c8c84c357739b9466ad1 to your computer and use it in GitHub Desktop.
Iterate over all characters of a NSString as NSStrings.
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
typedef void(^StringEnumerationBlock)(NSString *characterString, NSUInteger index, BOOL *stop); | |
- (void)enumerateCharactersUsingBlock:(StringEnumerationBlock)block { | |
NSParameterAssert(block); | |
BOOL stop = NO; | |
for (NSUInteger i = 0; i < self.length; i++) { | |
const unichar character = [self characterAtIndex:i]; | |
NSString *characterString = [NSString stringWithCharacters:&character length:1]; | |
block(characterString, i, &stop); | |
if (stop) { | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment