1
  unsigned int bytes[] = {153, 3, 1, 0, 0, 4};

i used this

for(id b in bytes){

      }

got an erro like

The type 'unsigned int *' is not a pointer to a fast-enumerable object

2 Answers 2

1

The code you're using as an example is just plain old C:

unsigned int bytes[] = {153, 3, 1, 0, 0, 4};

So to work with bytes you'd need to do things the plain old C way:

for (int i = 0; i < sizeof(bytes); i++) {
    // do something with bytes[i]
}

If you want to do things using Objective-C's features, you'd use NSArray and NSNumber:

NSArray<NSNumber*> *numbers = @[@(153), @(3), @(1), @(0), @(0), @(4)];

and then you can use fast iteration:

for (NSNumber *number in numbers) {
    //do something with number
}

The type 'unsigned int *' is not a pointer to a fast-enumerable object

You get that error because for...in is an Objective-C construction that only works with objects that support NSFastEnumeration. See the NSHipster post on NSFastEnumeration/NSEnumerator for a more extensive explanation.

Sign up to request clarification or add additional context in comments.

Comments

1

One method...

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]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.