I learned iOS programming for the BeMyApp Hackathon, and finally got a chance to experience Objective-C first hand. With just two days I only managed to learn one particular way to do a task, so some clumsiness are mine. Nonetheless I'd like to jot down my first impressions.
Before the hackathon, the only thing I knew about Objective-C was that there are a lot of square brackets. That's the syntax for passing messages. I didn't have time to learn the difference between function calls and message passing, and I need to look into that. But otherwise I don't really see why people make such a big fuss out of it. Yes, it's clumsy. But conceptually it doesn't seem too complex. For me, I keep forgetting how to define a function with parameters, so I had to refer to the existing functions. But I'm sure I'll get used to the syntax in no time.
Specifying UI components
When I picked up Android, the visual UI design tool was still in its infancy, and not very usable. As a result I always specify my UI via XML. In iOS, however, I had to use the visual tool. There is a list of UI components on the side bar, and I drag and drop them onto the screen designer. I like that there are helper lines to match up elements horizontally and vertically. But then I had to add 5 buttons, and I wanted to space them evenly. That was no obvious way to do it. I went into the source, but everything has absolute co-ordinates, unlike Android, where I can specify the relative positions and use margin to space them out. Since it was just for the demo, I placed the buttons roughly where they should be, and moved on.
Linking UI components with code
Next I needed to hook up the buttons so they do something when you click on them.
The basic idea is the same in iOS and Android: you define a click handler, and link the button to it.
In Android, you can do the linking in two ways:
onClick function in XML by name or
assign an ID to your button in XML, and do the association in Java code.
In iOS I only learned one way:
- Define a function in the ViewController class with the signature
- Open the graphic editor for the
- Right-click and drag the button to the icon of the ViewController.
- All the
IBActionfunctions will be displayed. Choose the one you want.
I'm not familiar with the right-click and drag gesture, so this feels a bit clumsy. But it's not a big deal.
The biggest pain point is actually the project files. Like any sensible team we use source control to share code. But it wasn't clear which project files need to be checked in. And when we add a new class the project files change in some opaque way. I spent so much time helping team members deal with git merges that it was getting a bit tedious.
This is even more tedious than git merges. We have to collect UUIDs from all the devices of our team members, create a list, embed that in the build, etc etc. Android is much simpler - just distribute the apk file. The flip side is that you cannot control who gets to install your Android beta binary, so each platform has its own annoyance.