Illep
Illep

Reputation: 16841

Adding NSData to a NSData Byte Array

I want to add an image to a byte array. The following code gives me an error. I think i have not done it correctly.

Error

Field has incomplete type 'NSData *__strong[]'

In the .m file

@interface MyViewController() {

    NSData *byteArray[];

}

inside the method

NSData *imgD = UIImageJPEGRepresentation(img1, 0.1);

NSData *imgD2 = UIImageJPEGRepresentation(img2, 0.1);        

NSData *imgD3 = UIImageJPEGRepresentation(img13, 0.1);

 [byteArray addObject:imgD];

 [byteArray addObject:imgD2];

 [byteArray addObject:imgD3];

Upvotes: 1

Views: 195

Answers (1)

V.J.
V.J.

Reputation: 9580

You can add an image to an array. Use NSMutableArray instead of NSData*[]. 

In the .m file

@interface MyViewController() {    
    NSMutableArray *byteArray;    
}

inside the method

byteArray = [[NSMutableArray alloc] init];   
NSData *imgD = UIImageJPEGRepresentation(img1, 0.1);    
NSData *imgD2 = UIImageJPEGRepresentation(img2, 0.1);            
NSData *imgD3 = UIImageJPEGRepresentation(img13, 0.1);

[byteArray addObject:imgD]; 
[byteArray addObject:imgD2];
[byteArray addObject:imgD3];

Upvotes: 1

Related Questions