Simplest way to extract first Unicode codepoint of an NSString (outside the BMP)?
问题 For historical reasons, Cocoa's Unicode implementation is 16-bit: it handles Unicode characters above 0xFFFF via "surrogate pairs". This means that the following code is not going to work: NSString myString = @"𠬠"; uint32_t codepoint = [myString characterAtIndex:0]; printf("%04x\n", codepoint); // incorrectly prints "d842" Now, this code works 100% of the time, but it's ridiculously verbose: NSString myString = @"𠬠"; uint32_t codepoint; [@"𠬠" getBytes:&codepoint maxLength:4 usedLength:nil