简体   繁体   中英

Create an NSData object from a String

My app requires the ability to take a String and save it to an NSDictionary as an NSData object, such that when the NSDictionary is written to a .plist file the resulting file contains the data as <data>The String as the user typed it (no encoding)</data> . Is there anyway to do that without manually writing the XML for the .plist file?

Thanks in advance for any help.

There's no way to do what you want.

First, it makes no sense to claim that you don't want the string encoded. Encoding is the process of producing a byte stream from a string. Without encoding, there's no representation of the string. Strings are abstract. They have no concrete representation in and of themselves. Only encoding produces that.

Anyway, that's just not how NSData objects are serialized to property list files. Even if you manually wrote the file, it wouldn't really be a correct property list file and no other property-list-reading program would be able to parse it. How did you come to conclude that your app requires this ability?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM