0 randomly becomes 55?

88 views Asked by At

I have an app in which I pass an dictionary of type [string:[int]] from a swift file to an objective c file, then as NSDictionary. Through that process, the data formats get all screwed up, but in the end I am able to access each array of ints from a string, as would be expected from an NSDictionary. Unfortunately, somewhere along the line the integers get converted to type 'id', and to change that back to int, I did this:

NSLog(@"%d",(int)theThreeNotes[@"0"][0])

theThreeNotes[@"0"][0] should be 0, but it is logged as 55. How do you fix this?

1

There are 1 answers

3
Sulthan On BEST ANSWER

If the dictionary is passed to Objective-C, all the integers will become NSNumber instances. NSDictionary/NSArray cannot hold primitive values. That means you will have to call integerValue on the number, not cast it blindly to int.

Or just print it using:

NSLog(@"%@", theThreeNotes[@"0"][0])