Christmas 2008 - For the first time in several years I was going to be off from work for two straight weeks and my family had no plans go anywhere. Two weeks just hanging around the house. What was I going to do with myself?
I suppose I could have tackled some long neglected household repair, or I could have just kicked back and overdosed on Christmas movies and bowl games like I usually do this time of year. But instead, after lounging around for a day or so, a light bulb went off over my head. An iPhone application! I was going to try my hand at developing an iPhone application.
I've been an Apple user for several years, but I had absolutely no experience developing applications under OS X. I had never written a line of Objective C, I'd never used Apple's XCode Integrated Development Environment (IDE) and I'd never written a line of OpenGL. And did I mention that I didn't own an iPhone? Sound like a recipe for success?
There were two things I did have though. I had an iPod Touch and on the first day hanging around the house, I came up with an idea. So could a neophyte iPhone developer go from start-to-finish with an iPhone application in just two-weeks?
In this article, I'll walk through my two-week process and show you what I did. I don't have room to give you a complete tutorial, but I'll map out the basic process that I went through and provide some pointers to external resources to help you follow along. Did I succeed? Read on to find out, (But just don't tell my brother who works for Google building the competing Android cell-phone platform!)
So, where to start? In my case, the first stop was Amazon.com where I quickly zeroed in on a highly-rated book entitled Beginning iPhone Development. I couldn't wait for Amazon, so I braved the Christmas shopping crowds and found the book in stock at a local tech-bookstore. They only had two copies left and the proprietor said it was selling well, so maybe I wasn't the only one with this idea.
When I got home, I headed off to Apple's developer web site to sign up and download the development kit . If you want to use it yourself, you'll need a relatively recent X86-based Mac. The free kit includes a complete fully-functional iPhone simulator (Figure 1) where you can try your application out.
Figure 1: iPhone Simulator
To actually install your project on an iPod or an iPhone, you'll need to take the next step up the developer program ladder and pay $100. This will get you additional documentation, technical support, tutorials, encryption keys, and most importantly the ability to sell your application in the iTunes Application store. For myself, I wasn't sure how far I'd get. So to save my money, I initially made do with the simulator.
The main part of the development kit that you'll be interacting with is the Xcode IDE. That's where you'll to do all of your editing, compilation, profiling, user interface work, etc. Figure 2 shows the layout of a basic iPhone application inside the IDE.
Figure 2: Xcode IDE
In this window, you can see a list of the various files and directories in the project, along with the editing window where you'll spend a lot of time. I had never used Xcode, so it was a bit of a learning-curve to figure it all out. But the book and included project templates enabled me to get up and going quickly with a little "hello-world" application running inside the simulator.
In fact, you can get a basic iPhone application running with buttons, labels, images, etc. without writing a single line of code. Apple includes project templates for a number of different application types and given my short timeframe, my strategy was to start with an OpenGL-based template and modify it for my needs.
When setting up menus, buttons, forms, etc. for your application, you'll use Apple's Interface Builder (IB). Figure 3 shows the widget library from IB.
Figure 3: Interface Builder Widget Library
The basic idea is that you drag items from the library onto your application's window where you can arrange, group and customize then them as needed. Once you get everything set up, you'll use IB to link actions such press, scroll, etc. to your own code.
And speaking of code, all of the code in the template files is written in Objective C, and as mentioned earlier, I had never written a line of Objective C. Fortunately, Objective C is a superset of C. So in the interest of time, I intended to write most of my own code in C and only use Objective C where I needed to do user interaction.
Initially I didn't need much user interaction. I just wanted to set up a blank OpenGL canvas that would open when my application started. And the Open GL template provided by Apple took care of this for me. So with little work, I had my own application that I could start up on the simulator with a basic OpenGL canvas for me to draw to. Now would be he hard part. Creating the code to bring my idea to life.