我对objective-c不是很有经验,我需要为以下用例提供建议:
我正在为 ios 编写一个 React 本机模块,ios 端的一个本机方法接收一个包含整数的NSArray
(每个整数的值介于 0 和 255 之间)。
在我的 objective-c 代码中,我需要将此NSArray
转换为Byte bytes[]
以将其传递给我使用的一些 SDK。
如何进行转换?
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);
假设doWhateverWithBytes
接受Byte bytes[]