将 nsdata 对象合并为 nsmutabledata 对象
我相当确定我必须使用 NSMutableData 来解决这个问题,因为我将多次访问该对象并在获得数据后添加每个数据部分。
我面临的问题是我想要创建一个大的 NSMutableData 对象,该对象将由几个附加到可变数据对象末尾的小 NSData 对象创建,
我已经尝试了以下操作。
编辑://此方法现在可以正常工作并按预期附加数据。
- (void) constructRequest
{
NSData * protocolInt = [self addProtocolVersion];
NSMutableData * myMutableData = [[NSMutableData alloc] init];
NSData *first_data = [self addProSig]; //nsdata type
NSData *second_data = [self addAct]; //nsdata type
[myMutableData appendData:first_data];
[myMutableData appendData:second_data];
//etc
[protocolInt writeToFile:@"/Users/imac/Desktop/_dataDump.dat" atomically:YES];
}
首先,我什至不确定这是否是附加数据的正确方法,只是我看过几个示例相似的。 主要问题是,在这里的两行上
NSMutableData *first_data = [self addProSig]; //nsdata type
NSMutableData *second_data = [self addAct]; //nsdata type
我都有警告
初始化“NSMutableData * _strong”时不兼容的指针类型 'NSData *' 类型的表达式
任何帮助将不胜感激,也可能是我正在使用的更好的解决方案(如果有的话)。
I'm fairly sure I have to use NSMutableData for this problem as I will be accessing the object several times and adding each section of data once I have it.
The problem I am faced with is that I am wanting to create one big NSMutableData object that will be created by several small NSData objects that are append to the end of the mutable data object
I have tried the following.
EDIT: // This method now works and appends the data as its supposed too.
- (void) constructRequest
{
NSData * protocolInt = [self addProtocolVersion];
NSMutableData * myMutableData = [[NSMutableData alloc] init];
NSData *first_data = [self addProSig]; //nsdata type
NSData *second_data = [self addAct]; //nsdata type
[myMutableData appendData:first_data];
[myMutableData appendData:second_data];
//etc
[protocolInt writeToFile:@"/Users/imac/Desktop/_dataDump.dat" atomically:YES];
}
First of all I am not even sure if this is the correct way to append data, It's just that I have seen several examples similar.
The main issue is that on the two lines here
NSMutableData *first_data = [self addProSig]; //nsdata type
NSMutableData *second_data = [self addAct]; //nsdata type
I have warnings on both lines
incompatible pointer types initializing 'NSMutableData * _strong' wuth
an expression of type 'NSData *'
any help would be appreciated, Also possible better solutions that what I am using if there are any.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要摆脱这些警告,您可以像这样制作可变副本......
To get rid of those warnings you can make a mutable copy like this...