Daniel
Daniel

Reputation: 87

How can I access the int values of an object in an NSMutableArray?

I try to access some values in a NSMutableArray I created, but I only get some numbers (address?) if I try to access them.

I was able to initialize an array and can add and change objects with

[myNSMutableArray addObject:[NSNumber numberWithInt:10]]

and

[myNSMutableArray replaceObjectAtIndex:0 withObject:[NSNumber numberWithInt:47]

I also can print the value at index [0] with

NSLog(@"%@", [myNSMutableArray objectAtIndex:0]);

and I get 47 as expected.

But how can I access the integer value of the object in the array so I can save it tomyIntValue?

Upvotes: 0

Views: 647

Answers (1)

MKroehnert
MKroehnert

Reputation: 3737

int myIntValue = [[myNSMutableArray objectAtIndex:0] intValue];

Just have a look at the NSNumber class reference

Upvotes: 3

Related Questions