I'm running into a bit of a weird issue. Whenever I create a new text file in my iOS application, I set its encoding to be NSUTF8StringEncoding
. If I edit the file and input any characters with diacritics and save the changes, the diacritics render properly in some applications such as BBEdit, TextMate, cat and vi but not in others such as TextEdit, Quick Look and Pages.
I'm using the following code to save the contents of a UITextView to the plain txt files.
NSError *error;
NSString *dataString = self.textView.text;
BOOL savedChanges = [dataString writeToFile:fullPath atomically:YES encoding:NSUTF8Encoding error:&error];
if (!savedChanges)
{
// Pop up an alert saying something went wrong.
}
The unix file
command reports that the saved file is indeed "UTF-8 Unicode text, with no line terminators"
What's even weirder is if I save the file again without changing the contents of the text, the file will then render properly in Quick Look & TextEdit on my Mac.
Any help would be appreciated.