A couple of weeks ago I was looking at the vast list of unfinished projects and random ideas i’ve accumulated over the last year or so and decided I needed to choose one and finish it. That’s when I decided to concentrate on my next game, Gravity Pods 2. As soon as I started on that, I had the epiphany that it would make a great game for the iPhone.
So, while I’ve been cranking on the Flash version of the game, I started to look into learning Objective C 2.0 and iPhone development. The transition is not an easy one. ActionScript, JavaScript, Java, C, C#, C++, PHP, etc. are all pretty similar in terms of basic syntax. Even Python is not that foreign. Most do stuff like this:
myObject.someMethod(someParam);
or maybe
myObject->someMethod(someParam);
But what the hell is this???
[myObject someMethod:someParam];
OK, that’s probably the worst of it, and you get the hang of it pretty quickly. There’s other basic syntactic weirdness like “-” instead of “public” and “+” instead of “static” and @property and @synthesize for making getters and setters (which is kind of cool – I wish ActionScript had that), and the string syntax @“someString”. All in all, you look at your first Objective C program and you’re like, “WTF???”
Then there’s interface builder. You make an interface by laying out visual components. This creates a xib file. xib is the updated, xml based version of nib files, which have been around in Mac dev forever. It’s a view – think of it as an MXML file. And it’s linked to an actual class, the controller – think code behind maybe. But linking elements from the xib to the controller class is a bit odd. Instead of simply giving your text field an id that becomes accessible as a property in the controller, you have to create an “outlet” in the controller. An outlet is a special variable to link to an element in the xib. Then you have to do this funky drag and drop connect the blue line from the text field to the “file’s owner” icon, which will pop up a list of outlets for you to choose. Same thing for events. You create an IBAction in the controller – which is an event handler – then drag between your button or whatever and the file’s owner and choose the action. Weird. Actually, that’s how all the books and tutorials tell you to do it. But I discovered the connections panel which at least gives you feedback of what outlets are available, what is connected to what, and what remains unconnected.
Anyway, not trying to scare you off. Just pointing out that it’s a very different paradigm of programming and that if you want to learn it, you need a decent resource. I’ve dug through a bunch of tutorials and sites. I got the prerelease Pragmatic book on iPhone development, which is pretty good, but I think walks you through a bunch of stuff without really explaining what and why you are doing too well. “Create the outlet like this, create the label like this, drag from here to here to connect them, save and compile!” Huh? It works, but what the hell did I just do? Could I do it again on my own? Um … maybe, I guess.
But I just got this book yesterday:
Beginning iPhone Development: Exploring the iPhone SDK, by Apress. THIS is the book you want to get if you are … beginning iPhone development. I really love the way this book is written. It takes each little step of the process and tells you exactly what it is for and why you are doing it. It sounds tedious, but I’m sitting there reading it going, “ahhhhh….”, “oh….”, “ah… I see now!” At the end of each project, you not only made a functional app, but you understand each and every line of code you wrote, and what all those draggy-droppy blue line things did. I got through three and a half chapters last night after dinner. Before that I was a bit overwhelmed but optimistic. Now I’m just plain excited to learn more.
I’ll probably be posting some AS3-Objective C comparisons later on, if only because teaching is a great way of learning. In the mean time, Andy Jacobs has already started that kind of thing here: https://andyj.be/blog/. Check it out. And get that book.