Saturday, August 18, 2012

Debugging with ARC and Zombies enabled

If you tried to debug your app with zombies enabled under ARC, you may have noticed that you don’t get zombies anymore. That’s most probably because of a bug in the Foundation framework that affects iOS 5 and OS X 10.7. This bug prevents ARC from "cleaning up" instance variables at deallocation-time according to Apple Technical Q&A QA1758. Apple strongly encourages you to run your app on an iOS 6+, or OS X 10.8+ system when debugging with Zombies.
In the meantime, you can workaround this bug if you are using ARC and trying to debug zombies on older systems. Just compile this NSObject+ARCZombie.m file in your project and ivars will be automatically deallocated under ARC when zombies are enabled, as it should be.
Now you might think Hey, you are swizzling dealloc, isn't that dangerous? Well, yes it is, but note that the dealloc method is only swizzled when the NSZombieEnabled environment variable is enabled, so even if this code slips in your release build, il will cause no harm at all.

UPDATE: After I posted this, Greg Parker warned me on twitter:

@0xced That'll cause over-release of associated objects on some systems.

So use this workaround with care and remember that the best solution is what Apple recommends: run your app on an iOS 6+ or OS X 10.8+ system when debugging with Zombies.

Wednesday, August 08, 2012

Prepare your apps for the iPhone 5

Earlier today, my friend Peter Steinberger asked:

Does anyone know what does “special iPhone Simulator tweaks” are? I’d love to test my stuff with different resolutions.

So I investigated, and found a pretty elegant solution. Without further ado, here is how to change the size of the iOS simulator in order to test your apps in resolutions never seen before.

  1. Download File.txt into ~/Library/Application Support/iPhone Simulator (don't change the name of File.txt)
  2. Edit /Applications/ (Retina).deviceinfo/Info.plist and add the following keys:
  3. Add setenv("CLASSIC", "0", 1); just before UIApplicationMain in your main.m file in order to support any simulator version.
  4. Quit the iOS Simulator app

You are now ready to test your apps on the rumored 640×1136 new iPhone.

This hack works on Xcode 4.4.1+ and the iPhone 5.1+ Simulator with the iPhone (Retina) device.