Reputation: 12630
I have an iPhone application using Core Data with an SQLite database in the bottom. I'm writing some text content from the database to a file, but special characters such as Å, Ä and Ö are corrupted in the file (they show up just fine in the application).
When creating and inserting data, I am not using any special encoding. I'm just taking the NSString (entered by the user in a UITextField) and putting it in my persistent objects. When saving the file, I use the following code:
[csvString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
I tried adding a BOM to the beginning of the text ("\xef\xbb\xbf") but it is still corrupted. Anyone has any ideas where the problem might be?
Examples of corrupted characters: å becomes ö, ä becomes ä
Upvotes: 2
Views: 1497
Reputation: 24455
Your example corruptions looks like correct UTF-8 characters interpreted as ISO-8859-1. How are you viewing the file? Are you sure that the viewer you are using is actually interpreting the file as UTF-8?
Upvotes: 2
Reputation: 46718
Have you tried changing the encoding to NSUTF16StringEncoding?
Upvotes: -1