You can speed it up -characterAtIndex:by first converting it to an IMP form:
NSString *str = @"This is a test";
NSUInteger len = [str length];
SEL sel = @selector(characterAtIndex:);
unichar (*charAtIdx)(id, SEL, NSUInteger) = (typeof(charAtIdx)) [str methodForSelector:sel];
for (int i = 0; i < len; i++) {
unichar c = charAtIdx(str, sel, i);
NSLog(@"%C", c);
}
EDIT: It looks like the CFStringLink contains the following method:
const UniChar *CFStringGetCharactersPtr(CFStringRef theString);
This means that you can do the following:
const unichar *chars = CFStringGetCharactersPtr((__bridge CFStringRef) theString);
while (*chars)
{
chars++;
}
If you do not want to allocate memory for copying the buffer, this is the way to go.
source
share