Replacement for NSData.description?

Hi,
I have old code based on Apple's sample code (Sketch, I think) that uses the NSData.description method to return a hex string that can be saved in PLIST format, in its document data.

My app then reads that format for the document and recreates objects as needed.

I don't see any documentation for NSData.description changes, despite that this has apparently broken a number of apps that rely on it.

This was Apple sample code, and was an Apple sanctioned method of dealing with this type of data.

Is there a replacement for it? If not, should I move away from NSData to store information, if it cannot save data in a human readable format anymore?

Thank you,
  • Chilton

Description methods are meant for debugging. You should not rely on their output in other contexts. This is well-known lore but, alas, the documentation is lacking. The best discussion of this is in the CFCopyDescription(_:) docs:

You can use this function for debugging Core Foundation objects in your code. Note, however, that the description for a given object may be different in different releases of the operating system. Do not create dependencies in your code on the content or format of the information returned by this function.

Unfortunately this clear statement is not reflected elsewhere in the docs (r. 54383819).



Coming back to your problem, you mentioned property lists but it’s not clear that you’re using property lists. If you are, be aware that NSData is a property list type. You don’t need to encode it to put it in a property list; you can just add it to the property list directly.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Replacement for NSData.description?
 
 
Q