Search code examples
iphoneiosios5ios4

How to concatenate 3 NSData variables


How to concatenate 3 NSData variables ?

NSData *iv;
NSData *salt;
NSData *encryptedData;

I need to join these to a single variable. Can any one show me a way.


Solution

  • use an NSMutableData object and the method -(void)appendData:(NSData *)otherData

    Edited to add example :

    NSMutableData *concatenatedData = [NSMutableData data];
    [concatenatedData appendData:iv];
    [concatenatedData appendData:salt];
    [concatenatedData appendData:encryptedData];
    // and now you have all of the data in the single variable "concatenatedData"