I\'m trying to loop through a NSString, character by character, but I\'m getting a EXC_BAD_ACCESS error. Do you have an idea how to do this right? I\'ve been googling for hours
characterAtIndex:
returns a unichar
, which is declared as typedef unsigned short unichar;
The format specifier you are using in your calls to NSLog
are incorrect, you could just do NSLog(@"%u",[self.text characterAtIndex:position]);
or NSLog(@"%C",[self.text characterAtIndex:position]);
if you want the actual character to print out.
Also, as a result of unichar being defined the way that it is, it's not a string, so you cannot compare it to other strings. Try something like:
unichar textCharacter = '.';
if ([self.text characterAtPosition:position] == testCharacter) {
// do stuff
}