本文介绍了NSMutableData如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题使用 NSMutableData

我定义了一个 NSMutableData * receivedData ,并尝试复制几个 NSData * 数据到 receivedData 。我只是调用 [receivedData appendData:data] ,但是显示的数据未被复制:

I defined one NSMutableData *receivedData, and tried to copy several NSData* data to the receivedData. I just called [receivedData appendData:data], but appears the data is not copied:

....
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


$ b

谢谢。

Thanks.

推荐答案

检查 receivedData == nil 。如果是这样,那么你可能忘了初始化它。例如:

Check if receivedData == nil. If so, then you might have forgotten to initialize it. For example:

receivedData = [[NSMutableData alloc] init];

然后在不再需要时释放:

Then release it when you don't need it anymore:

[receivedData release];
receivedData = nil;

这篇关于NSMutableData如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:39