我有一个问题与NSMutableData
一起使用。
我定义了一个NSMutableData *receivedData
,并尝试将多个NSData*
数据复制到receivedData
。我刚刚调用[receivedData appendData:data]
,但似乎没有复制数据:
....
NSLog(@"get data! Received %d bytes of data",[data length]);
// output is not zero, say 1231.
[receivedData appendData:data];
NSLog(@"after append! length is %d bytes of data",[receivedData length]);
// showing zero
感谢。
答案 0 :(得分:15)
检查是否receivedData == nil
。如果是这样,那么您可能忘记初始化它。例如:
receivedData = [[NSMutableData alloc] init];
然后在你不再需要它时释放它:
[receivedData release];
receivedData = nil;