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
}