Wednesday, January 28, 2009

Lessons in iPhone Development

I've been spending a lot of time working on iPhone projects, and I've learned a couple of important lessons (the hard way).

1) Computationally intensive code runs slow on the iPhone. When it comes to raw number crunching, code ran 60 times slower on the iPhone than on my old MacBook Pro. If it takes one second on the simulator, it will need at least a minute on the phone.

Even worse, something that is so fast that you cannot even see it in the simulator may take several seconds to complete. This can cause all sorts of unexpected problems. The lesson here, test everything on the phone as early as possible.

2) The camera image picker is apparently designed to be used only once then thrown away. The photo library picker (even though they're the same class) doesn't seem to have this limitation.

I put both in tabbed windows, so the user could easily switch images. The user could return to the photo library picker as many times as they wished. However, the camera picker would only take a single picture, then it would only display the last picture taken. There seems to be no way to reset it.

Bottom line, use them as modal views and toss them. Instantiate a new picker the next time you need one.

3) Memory management is hard. Even when I thought I'd been careful, when I tested it in Instruments, I had leaks all over the place.

4) Using Objective-C serialization to save off large collections of objects can be very slow. Encoding the collection into a NSData object, then saving that can vastly improve performance. At least, it did for me.

I'm sure there's more, but that's all I can remember at the moment.

-Rich-

No comments: