inserted type does not match in NSMutableArray

52 views Asked by At

I am facing a very wierd problem. I try to understand what is going on. Simply speaking, I was trying to insert a NSInteger to a NSMutableArray. keys is the NSMutableArray. key is of type NSInteger.

[keys insertObject: [NSNumber numberWithInteger: key] atIndex:insPoint];

In xcode console. I can see key=(NSInteger) -1. so type is NSInteger and value is -1. However, when I run above codes and check what is in keys. It shows (_NSCFNumber *) long 7205759403792935. If I changed the code to

[keys insertObject: [NSNumber numberWithInt: key] atIndex:insPoint];

It shows correctly (_NSCFNumber *) int -1. I also tried NSLog with numberWithInt and numberWithInteger

NSLog(@"%@",[NSNumber numberWithInteger: key]);
NSLog(@"%@",[NSNumber numberWithInt: key]);

They all show -1. I also tried

NSInteger a=-2;
[keys insertObject: [NSNumber numberWithInteger: a] atIndex:insPoint];
#also have some wierd number, but it works for positive number 

What is the problem? Any suggestions?

1

There are 1 answers

1
AudioBubble On BEST ANSWER

7205759403792935 is more than 32 bits. The value is -1 as a 56 bit integer.