Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
objective-c中的字节数组_Objective C_Arrays_Byte - Fatal编程技术网

objective-c中的字节数组

objective-c中的字节数组,objective-c,arrays,byte,Objective C,Arrays,Byte,如何在Objective-C中创建字节数组 我有一些像这样的数据:0x12、0x23、0x34、0x45、0x56、0x67、0x78、0x89、0x12、0x23、0x34、0x45、0x56、0x67、0x78、0x89,我想把它们准备成字节数组。您可以简单地使用纯C语法,这在Objective-C中是可用的: const char myByteArray[] = { 0x12,0x23,0x34,0x45, 0x56,0x67,0x78,0x89, 0x12,0x2

如何在Objective-C中创建字节数组


我有一些像这样的数据:
0x12、0x23、0x34、0x45、0x56、0x67、0x78、0x89、0x12、0x23、0x34、0x45、0x56、0x67、0x78、0x89,我想把它们准备成字节数组。

您可以简单地使用纯C语法,这在Objective-C中是可用的:

const char myByteArray[] = {
    0x12,0x23,0x34,0x45,
    0x56,0x67,0x78,0x89,
    0x12,0x23,0x34,0x45,
    0x56,0x67,0x78,0x89 };

使用mouviciel给出的纯C解决方案,或者阅读和的类说明。

非常感谢。。。亲爱的mouviciel,它工作正常。如果使用无符号字符有什么区别?我喜欢C字节数组,但是如果您希望在NSArray中包含多个字节数组,该怎么办<代码>ARC不允许将非目标C指针类型“const char*”隐式转换为“id _Nonnull”
。我喜欢下面来自@Georg的答案<代码>NSData*数据=[[NSData alloc]initWithBytes:字节长度:sizeof(字节)]?应更新这些链接-NSData:-NSMutableData: