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...



MathJax v2.1 works beautifully on iOS 6.1 !!

Tested MathJax v2.1 on iOS 6.1 using same steps mentioned in my previous post, and it works beautifully as expected. Tested on both iPhone/iPad simulator and my iPhone 5, all works perfectly.



Also checked app size on iPhone 5 using "Usage", and as below it's only 7.2MB. You definitely got plenty of space for your other stuffs!

I think if you have to time to do more research, for example, follow steps mentioned in this post by Davide Cervone you should be able to trim down even more! Have a go and welcomed to share your experience with everyone.

Well done, MathJax guys, thanks for the excellent work!

Saturday, 9 March 2013

Passed-by-value struct argument contains uninitialized data

While working on the card game, keep getting this annoying warning: "Passed-by-value struct argument contains uninitialized data" but couldn't work out anything wrong....


Later realised it's complaining about the "tmp" CGPoint variable returned from the other method "getCardPositionWithIndexForPlayer". Checked that method and at the beginning it's just a simple declaration, in the middle there're 2 few different "if" condition checks that assign value to the variable, and then return the value.


CGPoint tmpPoint;
....
if ((player.position == PlayerPositionLeft) || (player.position == PlayerPositionRight)) {
....
} else if ((player.position == PlayerPositionBottom) || (player.position == PlayerPositionTop)) {
....


}

return tmpPoint;



I guess the compile is complaining that that's no trailing "else" at the end of the last "if" block - in case there's a condition not covered. So I fixed it by changing the 2nd "if" check to "else" only, as if the player is not at left or right position, must be either at bottom or top. Problem solved.

You get what you paid for

Sometimes you might wonder why Apple charged so much for their products. Just give you 2 examples I heard from friends.

First was the "Lightning to USB cable", Apple charged AU$25.00 in Australia, but you can also get something similar from ebay for about AU$5.00. So how bad is the quality of the cheap ones if it cost only 1/5 of the Apple ones?

A friend of mine got one from an Hong Kong ebay seller and she was quite happy with it for a few weeks. Then one day somehow she found the cable was sort of stuck with the phone, so she pulled a little bit harder and the white plaster cover fell off. That is, from this

to this:


She was a bit shock and since then the plastic thing came off quite easily. As it's still working ok, she later got her boy friend to apply some super glue on it and that fixed the problem...

The second one was also similar, but with a different product - a "Lightning to 30-pin Adapter" which Apple charged AU$35.00 in Australia, and you can get something similar from ebay for around AU$3.00, which is more than 10 times difference!

Another friend who bought one from ebay, found the gray coloured plastic thing around the 30 pin adapter side keep falling off whenever he try to unplug the adapter as shown below. And as shown below he could then easily pop out the whole circuit board by pressing on the lightning connector side.

My friend was however very lucky as this happened the 2nd day after goods received. He complained to the ebay seller who was also based in Sydney, and received another new one within a few days. When asked about sending the faulty one back, the seller doesn't even want it (May be it's so cheap that it doesn't worth the effort??) I told him about the super glue fix, he tried it and that works too. He now got 2 functioning adapters for the price of one, and was very happy about it...

So would you pay 5 or 10 times more for accessories from Apple shop? Both my friends recon they still saved a lot even with the extra cost of a super glue ... :-)

[Update Oct/2013]
I bought one of those lightning USB cables, and looks like it killed my MacBook Pro. See this post for further details...

So, definitely don't recommend to use any of those cheap cables on your Mac!!

Tuesday, 5 March 2013