1

In my app I hold a int in a Singleton which I set from ClassA. Then in ClassB I grab that int from the Singleton like so:

int myInt = [Singleton sharedSingleton].scoreInt;

Then, since NSDictionary only supports NSNumber and not int, I do this:

NSDictionary *theDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
            [NSNumber numberWithInt:myInt], @"Score", nil];

The problem is that I always get EXC_BAD_ACCESS error. The only thing that shows up in the console is (gdb) in blue. I also have NSZombieEnabled set to ON.

myInt is not nil, confirmed with NSLogs. Is there any reason for this? How can I fix this?

Thanks!

SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191
  • 2
    [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:myInt, @"Score", nil]; there is a closing ] missing after myInt ??? – Shubhank Jan 22 '12 at 08:14
  • Btw, what do you mean by "myInt is not nil"? It's an integer, it can't really have the value of an object.... –  Jan 22 '12 at 08:17
  • Sorry that was just a typo I will edit the post to add the bracket. And @H2CO3 I mean that it is always a number so there is no funky business going on. – SimplyKiwi Jan 22 '12 at 08:28
  • code looks valid..problem can be somewhere else..try breakpoints in your coed and check if it really crashes on dictionary ..also post some more code..where you have this dictionary – Shubhank Jan 22 '12 at 08:40
  • Can you post your singleton class's code? I suspect the problem may lie there. – Nick Lockwood Jan 22 '12 at 08:47
  • 2
    Do a backtrace and post the results. At the (gdb) prompt type: bt – Jeshua Lacock Jan 22 '12 at 10:07
  • Also, try using a NSNumber variable. That way you can narrow it down a little more. – Jeshua Lacock Jan 22 '12 at 10:08
  • try to enable exception as suggested in [run-stop-on-objective-c-exception-in-xcode-4](http://stackoverflow.com/questions/4961770/run-stop-on-objective-c-exception-in-xcode-4) and then verify where the exception is thrown. Hope it helps. – Lorenzo B Jan 22 '12 at 11:30
  • @JeshuaLacock Ok I posted it in the original post. Also if I use a NSNumber variable it either crashes at the place where I create the variable OR at the same place as it is now. – SimplyKiwi Jan 22 '12 at 22:12
  • @NickLockwood I posted the Singleton code in the original post. What I do is just make ivars for the objects I need and then setter and getter them. I do (assign) for all the properties. – SimplyKiwi Jan 22 '12 at 22:17
  • It seemed that deleting the app on the device and reinstalling it made it work. Odd though, any reason for this? – SimplyKiwi Jan 22 '12 at 22:28
  • After re-testing for the past few hours, there has been no crashes so I think this issue is resolved. Thanks again everyone for the help/tips! – SimplyKiwi Jan 23 '12 at 02:26

0 Answers0