Thursday, May 23, 2013

Delving into iOS for a week

I've been curious about writing native mobile apps for a while. 

In term of programming background, I've travelled from C++, to Java, naturally made my way to Groovy - experimenting other JVM based language is fun- and lately, I have been more involved in JavaScript. With web development  experience, writing HTML5 web mobile app is so much fun: playing around with jQuery mobile, cool HTML5 capabilities, JS framework variety... And if you really want it on web store, use Cordova for packaging it into hybrid app.

But still, it is not the same 'look and feel' and user experience. So, I'd like to know what it takes to write native apps. Apart from Cordova, I have no real experience with native apps...  And I've got this brand new iPad mini from my birthday.

Let's take a deep breath and make the plunge. Delving into iOS for a week. No fear. What can I learn in a week?

Googling around, looking for books to read, I eventually bought ePub version of Programming in Objective-C. I started reading it from start (you've got to do things right, you're learning a new language, take it seriously) and then... I just jumped to random sections. I was too eager to investigate "new" stuff like protocols, dynamic typing and blocks.

Objective-C sounds familiar. Indeed, Objective-C is a superset of C; My first surprise comes on how you call a method on an instance. You actually don't call a method, you send a message. I found this interesting blog discussing it: it's not just syntax hype! Digging around, I learn Objective-C derives its object syntax from Smalltalk. The difference between calling a method in C and sending a message in Objective-C is in how the code referenced by the method or message name is executed. In C/C++ language, methods are (in most cases) bound at compile-time whether in Objective-C, the target of a message is resolved at run-time which brings me to dynamic typing! Man I love that. Just like in Groovy (did I already mention I'm Groovy addicted? Co-founder of RivieraGUG :-) ?) you've got the type id, same as def (I don't really like the name here. Id makes you thing of unique identifier) which means a pointer to unknown object (see the difference from void *). Dynamic typing offers a wide flexibility in a way you can design you program. Another very close concept Obejctive-C/Groovy is categories: even the syntax is close!

Second surprise (I'm less enthusiastic about it, yo be honest) comes with property vs instance variable. It's obviously nice not to have to write your getter/setter methods yourself although with lazy instantiation pattern you often do write them and then you end up needed to use synthesize keyword which I find a bit verbose. Not to say all the keywords you have to precise around your property. I definitively think there is room for improvement here. Properties bring me to memory management, another topic is  worth digging, but I work with iOS6 and I use ARC (autmatic reference counting) so I can delay that for next week . Enough theory.

Launching Xcode to build command line application is ok for the first day. But I soon get frustrated, the fun of mobile app is mostly in graphical app. Games.

I remembered a recommendation from a friend of mine to follow the Stanford iOS classes. Those classes are available on iTunes. You can download them for free. And guess what? From the first lecture you start building a matching card game: Matchismo. That is what I want! Stanford classes are 19 sessions of 1h-1h30 each. During the lecture, you go through Objective-C concepts, Foundation libs, and Cococa Touch libs at the same time. Live demos are really good - my preferred part - I don't have time for the assignments but I like live coding at the same time than Paul Hegarty (Fortunate I have the pause option). With the video comes the very detailed slides with annotated screen shots (amazing learning support) and assignments. You can read this blog great post on 2011 classes if you want further feedback.

The good part of video classes is that it's easier to learn a tool like Xcode. In a book, you're flooded with screenshots when it comes to explain Xcode. I'd rather watch a video than going through pages of text and photos. I didn't have time to watch them all - went through half of them - but I will carry on for sure.

Starting a new project in Xcode, using storyboard and you get a feeling of language workbench. You're so well assisted by the IDE that you're not just writing code, you're drawing code: you're holding ctr key + drag and drop to generate action and outlet, Xcode interacting with you which name you want to give etc...  You're manipulate the abstract representation of a program with the tools provided by the editor. You code feels like natural language. You can pick very descriptive variables name, you're so well assisted by Xcode auto-completion that you can think in higher abstraction level.

Eventually, what did I manage to do?
After a week I manage to write my first game: Visualize (really inspired by classes). I even get through apple certificate hell to get my app running on my device. Horray! I didn't have time to publish it though(not enough polished to be published to App Store).

If you starting on iOS, with some OO programming background, I would definitively advise you to:
- watch  iOS Stanford classes,
- get your hands into code from day one.
- and have fun!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.