As an iPhone developer you have to handle low memory situations gracefully and clear as much memory as you can. These can often lead to unexpected crashes if your memory management has a bug somewhere. If you wish to catch these easily then do the following:
Go to your executable settings in Xcode and set the environment variable NSZombieEnabled to YES.
Go to System Preferences > Keyboard > Keyboard Shortcuts and add a shortcut for the iPhone Simulator menu item called “Simulate Memory Warning”. I set mine to command+1.
Add a breakpoint (cmd + option + B in Xcode) at “objc_exception_throw”.
Now run your app in the simulator under the debugger, and trigger memory warnings while working your app. Trigger often, at the places your app probably won’t expect them. In fact, try triggering as much as you can.
The shortcut you defined allows you to send the warnings while the mouse operates the app. Since NSZombie throws an exception on each message it receives, you’ll break exactly where you need.
Lately I’ve been introduced to the amazing world of photography. I was so amazed by this dazzling world that I decided to buy a new Nikon D90 and started a photography course. Expect more of these to come
Matalot has been featured in The Daily App Show! If you’re looking for a video review or just feel like seeing your favorite ToDo manager in public, go check it out in full size!
About two weeks ago I got a call from Roey, asking if I’d like to give a presentation about iPhone development. Obviously I agreed immediately. I chose to talk about CoreLocation, MapKit and CoreAnimation. These are a few technologies which, in my opinion, Apple designed and built very well. They make the iPhone a very fun development environment, and allows everyone to produce stunning apps with very little effort.
For those of you who don’t know Roey, he’s one of the better guys at iDigital, Apple’s reseller at Israel. The presentation took place at their store at Dizengoff Center (Tel Aviv).
Pictures are available from Picasa, and a PDF of the presentation, together with the sample code used in it is available here.
It’s been a while since the initial release of Matalot, and we have plenty of killer features in development. Meanwhile, we submitted a minor update with the following changes:
- Improved swipe to complete
- Some visual bug fixes
- Ads in the lite version
In my previous post about round rects in Quartz/CoreGraphics I posted a function I’m constantly using for drawing round rects. Today I found a bug in it. Apparently, all the round rects I drew were placed at 0,0 and so I never stumbled on the bug. Here’s a fixed version of the function:
Update: When writing this I wasn’t aware of CGRectIntegral() which is by far a better choice (as QC explains in the comments).
If you ever did extensive drawing with quartz, or any dynamic UI placement on the iPhone, you probably stumbled on this as well. I first saw it when drawing the oval shapes that show your priority in Matalot. The drawing code was very simple. Add an oval path, then fill + stroke. But to my surprise, when testing on the simulator the drawing was blurred. On my iPhone’s small screen it was less obvious, but blurred as well.
At first I thought something is wrong with my eyes. But then I added another instance of my view which rendered perfectly. There I was, with two instances of the same view, one blurred and one with the crisp anti-aliasing you’d expect from quartz. WTF?!
After many sleepless hours I suddenly remembered an article I once read about font rendering. In that article they discussed the rendering issues and how Windows draws fonts differently from OS X. Writing about this made me look up this article. It’s a very interesting reading, especially if graphics is your thing. Also be sure to read the linked articel about sub-pixel rendering.
Back to the subject, Apple and many others are using sub-pixel rendering to get beautiful anti-aliasing. Apple also prefers to stay loyal to the original drawing, even at cost of slight blurring. So perhaps my drawing just falls under this category? At this point I stepped back and checked out the exact placement and size of my views. And guess what, the blurred one was placed at non-integer pixels.
It turns out that quartz rendering gets blurred when placed at non-integer pixels! Rounding each pixel of the blurred view’s frame magically drew a beautiful result. How did I end up with non-integer values in the first place you ask? Simple. Placing a view at otherView.bounds.size.width / 2.0 may result in something like 45.5, and BOOM! You got blurred result.
Here is a quick function I use in order to make sure my views’ frames are with integer values. Feel free to use it as you wish.
So Matalot 1.1 is in active development and will have some really interesting new features. These features are what we believe Matalot needs. But what would you like to see?
Update: Fixed a bug when drawing at origin different from 0,0.
If you’re doing Quartz drawing code, you probably need or will need to draw a rect with round corners. Doing it for so many times, I just came up with this simple routine which will hopefully make your life easier: