Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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
Ios 如何在objc中循环字节数组_Ios_Objective C - Fatal编程技术网

Ios 如何在objc中循环字节数组

Ios 如何在objc中循环字节数组,ios,objective-c,Ios,Objective C,我用过这个 unsigned int bytes[] = {153, 3, 1, 0, 0, 4}; 有一个像这样的错误 类型“unsigned int*”不是指向快速可枚举对象的指针 一种方法 for(id b in bytes){ } unsigned int bytes[]={153,3,1,0,0,4}; int count=sizeof(字节)/sizeof(无符号整数); for(int i=0;i

我用过这个

  unsigned int bytes[] = {153, 3, 1, 0, 0, 4};
有一个像这样的错误

类型“unsigned int*”不是指向快速可枚举对象的指针

一种方法

for(id b in bytes){

      }
unsigned int bytes[]={153,3,1,0,0,4};
int count=sizeof(字节)/sizeof(无符号整数);
for(int i=0;i
您作为示例使用的代码只是简单的旧C:

无符号整数字节[]={153,3,1,0,0,4}

因此,要使用
字节
,您需要使用简单的旧C方式:

unsigned int bytes[] = {153, 3, 1, 0, 0, 4};
int count = sizeof(bytes) / sizeof(unsigned int);
for (int i = 0; i < count; i++) {
    NSLog(@"%u", bytes[i]);
}
类型“unsigned int*”不是指向快速可枚举对象的指针

之所以会出现这种错误,是因为
for…in
是一种Objective-C结构,它只适用于支持
NSFastEnumeration
的对象。有关更详细的解释,请参阅上的NSHipster帖子

for (int i = 0; i < sizeof(bytes); i++) {
    // do something with bytes[i]
}
NSArray<NSNumber*> *numbers = @[@(153), @(3), @(1), @(0), @(0), @(4)];
for (NSNumber *number in numbers) {
    //do something with number
}