Viewing NSData contents in Xcode

前端 未结 12 1997
我在风中等你
我在风中等你 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:27

    Unfortunately, none of the suggestions so far solved the problem of actually being able to quickly display the data inside NSData.

    I wrote a simple method that works the way I need it to. From the GDB window, I can type in print [Util dumpData:theData] and I will get nice, formatted output.

    +(void) dumpData:(NSData *)data
    {
        unsigned char* bytes = (unsigned char*) [data bytes];
    
        for(int i=0;i< [data length];i++)
        {
            NSString* op = [NSString stringWithFormat:@"%d:%X",i,bytes[i],nil];
            NSLog(@"%@", op);
        }
    }
    

    NsLog Output

    0:24
    1:0
    2:4
    3:0
    4:0
    5:0

提交回复
热议问题