I have to check each character in a given NSString for some condition.
When the string contains characters that would be represented in 4 bytes (in UTF-8 encoding) the result is not the character I expected.
NSString* oneCharString = [@"𝄞" substringWithRange:NSMakeRange(0, 1)];
The debugger shows:
It looks like an empty string. But the inspection shows some value (maybe a symbol for a non character ?).
If you want to get the first character of a string, you need to do it like this:
NSString *str = ... // the string such as @"𝄞"
NSRange firstRange = [str rangeOfComposedCharacterSequenceAtIndex:0];
NSString *oneCharString = [str substringFromRange:firstRange];
This code properly deals with composed characters.