Viewing NSData contents in Xcode

Viewed 21700

I am running Xcode and I would like to dump out a NSData*. The variable in question is buffer. Is there a way to do this through the UI or the GDB debugger?

This is what I see at runtime

Edit

I've moved my notes into an answer.

12 Answers

Xcode 11.4 (and probably earlier) supports examining the raw bytes of (NS)Data in the visual debugger. Set a breakpoint after the Data has been assigned, hover over the symbol until the popup appears, and click on the eye or info icon. Roll for dexterity to prevent the popup from closing on you by moving outside of the tiny target.

Tested with Swift but presumably works with C family languages, too.

(Note: the eye icon produces the output below which is nicely formatted but, uh... seems to be missing the final column of bytes?)

Xcode data view

For Swift code I'm doing the following:

When my program is stopped in a breakpoint I use the "Add expression" option and enter [UInt8](data) where data is my Data instance:

enter image description here

After that I can see the data contents:

enter image description here

Related