Question

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.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top