Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combine nsdata objects into nsmutabledata object

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.

like image 599
C.Johns Avatar asked Feb 24 '12 02:02

C.Johns


1 Answers

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
like image 127
Jeff Wolski Avatar answered Oct 06 '22 07:10

Jeff Wolski