0

I have an array that contains 16 items

NSArray *centreFreqValues = @[@250, @750, @1250, @1750, @2250, @2750, @3250, @3750, @4250, @5250, @5750, @6250, @6750, @7250, @7750];

I have a loop that performs various tasks:

for (int i = 0; i < 16; i++) {
//do some other stuff
int centreFreq = centreFreqValues[i];
NSLog(@" here is each integer %d", centreFreq);

}

but I'm getting the error message:

Incompatible pointer to integer conversion initializing 'int' with an expression of type 'id'

1
  • These are NSNumber instances, not int. So you can either use %@ instead of %d. Or you can get the intValue as Sandy described. Commented Jun 3, 2019 at 7:30

2 Answers 2

4

Try this. This way is easy.

NSArray *centreFreqValues = @[@250, @750, @1250, @1750, @2250, @2750, @3250, @3750, @4250, @5250, @5750, @6250, @6750, @7250, @7750];

for (id value in centreFreqValues) {

    NSLog(@" here is each integer %d", [value integerValue]);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Either You need to declare an array of integers or while assigning typecast to int.

[centreFreqValues[i] intValue] just check

2 Comments

so..NSInteger centreValues = [16]?
This answer is misleading. In Objective-C you can't create an array of integers (not directly) and you can't do this via typecasting.

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.