UITextView display corrupted after some operations

So, I have a UITextView subclass, that among other things, does some live syntax highlighting.


After *certain* operations, some of the text gets jumbled up into a string of gibberish characters. The length of the string stays the same, but all the characters are wrong. But as far as I can tell, this is purely cosmetic – if I step through the debugger, the string & attributedString of the text storage all look fine. It shows garbled in the "Debug View Heirarchy" as well, but the text shows up as correct in the Object Inspector. And if I copy the corrupted text, it gets pasted correctly.


I'm *sure* I'm doing something wrong somewhere with the syntax highlighting or *something*, but every avenue I've tried to investigate it makes it look like everything's fine.


Has anybody run into something like this before? Any idea what I might be overlooking?