Thursday, 21 March 2013

What works on the simulator might not work on the device

Still working on my card game, strangely although it works perfectly on the Simulator, when I tried to run it on the device it always crash at this line


    _gameCurrentPoints[0] = [NSNumber numberWithInt:0];
    _gameCurrentPoints[1] = [NSNumber numberWithInt:0];



The error message is as below, and it wasn't very helpful.


2013-03-21 20:50:37.679 Spade[6077:907] -[__NSCFString setObject:atIndexedSubscript:]: unrecognized selector sent to instance 0x1f876070
2013-03-21 20:50:37.681 Spade[6077:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setObject:atIndexedSubscript:]: unrecognized selector sent to instance 0x1f876070'
*** First throw call stack:
(0x344ee3e7 0x3c1df963 0x344f1f31 0x344f064d 0x34448208 0x1016fb 0xff44b 0xd5309 0xd927f 0x36413c65 0x363986ab 0x36398485 0x36397ddf 0x365d7d05 0x363ea99f 0x363e8fab 0xd9121 0xd52c9 0x36312abb 0x363878fd 0x360be309 0x3c5f95db 0x3c5fce45 0x344c21b1 0x3443523d 0x344350c9 0x3801333b 0x363512b9 0xd3d29 0xd3cb0)
libc++abi.dylib: terminate called throwing an exception
(lldb) 


The declaration is as below in the header file

@property (nonatomic, assign) NSMutableArray *gameCurrentPoints;


It's then synthesized with local variable as below


@synthesize gameCurrentPoints = _gameCurrentPoints;


It took me a while to realise, I should have use "retain" instead of "assign" as shown below. But I still don't understand why it works on simulator but failed on the device....



@property (nonatomic, retain) NSMutableArray *gameCurrentPoints;

Another lesson learned...



No comments:

Post a Comment