Brian Brian - 2 months ago 7
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

Edit

I've moved my notes into an answer.

Answer

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

Comments