2012-09-28 25 views

回答

1

我將其轉換爲一個數組

NSMutableData * rawData = [[NSMutableData alloc] initWithData:data]; 
    NSMutableArray * networkBuffer = [[NSMutableArray alloc]init]; 

    const uint8_t *bytes = [self.rawData bytes]; 

    //cycle through data and place it in the network buffer 
    for (int i =0; i < [data length]; i++) 
    { 
     [networkBuffer addObject:[NSString stringWithFormat:@"%02X", bytes[i]]]; 
    } 

那麼當然你可以調整對象你的networkBuffer(這是一個nsmutablearray)

5

但是,這使得編譯器大聲喊叫......

那是因爲mutableBytes*返回void*。它轉換爲char*來解決這個問題:

((char*)[mValues mutableBytes])[0] = v; 

你也可以使用replaceBytesInRange:withBytes:

char buf[1]; 
buf[0] = v; 
[mValues replaceBytesInRange:NSMakeRange(0, 1) withBytes:buf];