Brian Brian - 1 year ago 88
Objective-C Question

Viewing NSData contents in XCode

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?

:eThis is what I see at runtime


I've moved my notes into an answer.

Answer Source

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download