Viewing NSData contents in Xcode

前端 未结 12 1974
我在风中等你
我在风中等你 2021-01-31 09:51

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?

12条回答
  •  别那么骄傲
    2021-01-31 10:34

    Your data instance is empty.

    It wouldn't only display the address otherwise. -[NSData description] includes a printout of the contents of the data. The bytes are grouped in fours and printed in hex with a leading 0 placeholder:

    char arr[] = {0x1, 0x2, 0xA, 0x4, 0xF};
    NSData * dat = [NSData dataWithBytes:arr length:5];
    NSLog(@"%@", dat);
    

    2012-07-17 22:24:48.973 PrintDat[61264:403] <01020a04 0f>

    Using po dat at the debugger's command line will give you the same results, including the address:

    (NSData *) $1 = 0x00007f98da500180 <01020a04 0f>

    The contextual menu route that Anshu suggested also uses the description method.

提交回复
热议问题