1

I'm not very experienced with objective-c and I would need to advise for the following use case:

I'm coding a React native module for ios and one of the native methods on the ios side receives an NSArray containing integers (each integer has a value between 0 and 255).

In my objective-c code, I need to convert this NSArray to a Byte bytes[] to pass it then to some SDK I use.

How can I do that conversion?

1 Answer 1

3
NSArray* array = @[@(1), @(5), @(115), @(34)];

Byte* bytes = calloc(array.count, sizeof(Byte));

[array enumerateObjectsUsingBlock:^(NSNumber* number, NSUInteger index, BOOL* stop){

    bytes[index] = number.integerValue;
}];

doWhateverWithBytes(bytes);
free(bytes);

assuming that doWhateverWithBytes accepts Byte bytes[]

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer! sizeof(byte) gives Use of undeclared identifier 'byte'
Shouldn't it be the size of array instead?
The size of the array comes as the first parameter to calloc

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.