Thursday, May 15, 2008

iPhone Developer Program: First Steps

On Monday I checked my mail and to my surprise, I had an email from Apple saying my request to enter the iPhone Developer Program was accepted.

So I dutifully headed over to the Apple website, paid my £59 and waited a day for them to return my developer portal access.

Since then it's been pretty interesting... being able to put apps on the device has renewed my interest in iPhone development.  Objective C is still taking some getting used to but it's actually quite elegant in some ways.

For example, the thing that strikes you first is method calling/declaration.  You define the method as an english-language template with placeholders for the parameter arguments.

   - (void)showAlertWithMessage:(NSString *)message ErrorCode:(int)errorcode

Defines a method with complete name showAlertWithMessage:ErrorCode, that has to parameters defined in place: message and errorcode.

   [myobj showAlertWithMessage:@"Hello" ErrorCode:0]

Invoking the method on an object "myobj" is as simple as writing the template with the parameters in place indicated with colons.  The interesting thing is how the first parameter description is built into what you initially think of as the method "name" from C/Java.  In this case "showAlertWithMessage".

The method name in the Obj-C runtime is actually the complete concatenation of all of the descriptive parts.... quite elegant once you realise it is not a straight function/arguments type of statement.

However, the -/+ thing meaning instance/static(class) methods is still a bit odd though ;-)

Parsing an XML file looked straight forward and actually was once I realised that the Application is a bundle and therefore you need to use the NSBundle class to determine the path to it's resource directory (where all your files get placed when you build).  I find that the documentation while in-depth is not always that easy to navigate.

After being used to Java and Eclipse, Xcode is also not quite as good it feels a bit old-skool (lot's of key pressed and window switching required.. but then hey... that's osx for you;-) ).   The debugger works well and Xcode has some nice touches, like taking a screenshot from the device over the cable.

I'm currently doing some experiments on a driving game (surprise surprise) I have a steering mechanism using the accelerometer and the basics of 3d model import/display going.  It's harder to program than something like XNA but it's definitely interesting and, it's reminded me how much fun learning a new platform can be...