问题描述:

By putting a NSDictionary to a file I get an UTF-8 encoded XML file. I need to write data to a file in NSISOLatin1StringEncoding. Is NSDictionary UTF-8 only? How to achieve my goal?

网友答案:

Are you sure you need a file encoded as ISO Latin-1? The problem with all encodings other than some form of Unicode is that they can't represent all possible characters.

The encoding is surely the least of your problems. A dictionary's file representation is a property list file. It's unlikely that any code which requires Latin-1 encoding would understand that format. Indeed, the format is not guaranteed. It's not even guaranteed to be XML or textual. Property lists may be binary.

If you want to exchange data with a program that's going to use anything other than Cocoa's property list implementation, you should manually write the contents of the dictionary out in a format that's defined independently of Apple's property list format.

And, yes, if Cocoa does write the property list as XML, it's going to be UTF-8-encoded.

相关阅读:
Top