Reputation: 3007
this line of code gives the ans. 2 (which is right)
int def = arc4random() % 2;
NSLog(@"%@",[uniqueNumbers objectAtIndex:def]);
but when i use
int def = arc4random() % 2;
//NSLog(@"%@",[uniqueNumbers objectAtIndex:def]);
c1 = (int)[uniqueNumbers objectAtIndex:def];
NSLog(@"%d", c1);
it gives 115669616. where c1 is an integer. what is the problem?
Upvotes: 1
Views: 96
Reputation: 104698
NSArray
holds objects, not integers. that cast to int is not valid.
Upvotes: 0
Reputation: 44700
You get an NSNumber instance back.
You need to unbox it by calling intValue
on it, then you'll be good to go.
Johannes.
Upvotes: 3