简体   繁体   中英

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];
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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM