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

1 Answer 1

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];
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.