Skip to content

Instantly share code, notes, and snippets.

@edom18
Created March 9, 2014 16:26
Show Gist options
  • Save edom18/9450290 to your computer and use it in GitHub Desktop.
Save edom18/9450290 to your computer and use it in GitHub Desktop.
NSDataの中身を確認する方法 ref: http://qiita.com/edo_m18/items/b39fa31cd5c094fd05b6
NSLog(@"%@", [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding]);
void MQDumpNSData(NSData *data)
{
// データ配列のポインタを得る
const unsigned char *ptr = [data bytes];
unsigned long length = [data length];
// 取得したデータ分の文字列配列を確保
unsigned char s[length];
for (int i = 0; i < length; i++) {
// ptrポインタから文字列を取り出し、ポインタアドレスを先に進める
s[i] = *ptr++;
}
NSLog(@"%s", s); //=> 人間が分かる形で出力される
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment