Objective-c 中的字节数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/876598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Byte array in objective-c
提问by Raju
How can I create a byte array in Objective-C?
如何在 Objective-C 中创建字节数组?
I have some data like this:0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, that I want to prepare as a byte array.
我有一些这样的数据:0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89,我想准备一个字节数组。
回答by mouviciel
You can simply use plain C syntax, which is available in Objective-C:
您可以简单地使用 Objective-C 中提供的普通 C 语法:
const char myByteArray[] = {
0x12,0x23,0x34,0x45,
0x56,0x67,0x78,0x89,
0x12,0x23,0x34,0x45,
0x56,0x67,0x78,0x89 };
回答by Georg Sch?lly
Either use the plain C solution given by mouviciel or read the class description of NSDataand NSMutableData.
要么使用 mouviciel 给出的普通 C 解决方案,要么阅读NSDataand的类描述NSMutableData。

