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.
To get rid of those warnings you can make a mutable copy like this...
NSMutableData *first_data = [[self addProSig] mutableCopy]; //nsdata type
NSMutableData *second_data = [[self addAct] mutableCopy]; //nsdata type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With