1

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];
Illep
  • 16,375
  • 46
  • 171
  • 302
  • possible duplicate of [How to create byte array from NSData](http://stackoverflow.com/questions/8019382/how-to-create-byte-array-from-nsdata) – Razvan May 11 '15 at 08:21

1 Answers1

1
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];
V.J.
  • 9,492
  • 4
  • 33
  • 49
  • Please follow Objective-C coding conventions. Instance variables should always start with an underscore, not doing so is the cause of countless errors haunting beginners. And it would be better to make byteArray a property, not an instance variable. – gnasher729 May 11 '15 at 09:43