iOS Coding Conventions

Even for someone who thinks code, like art, is a form of expression and should reflect the characters of its creator, there is no denying that coding convention is a necessary evil for effective collaboration, especially for shipping production code. So far, my practice has been to cheery pick what makes sense from a number of recommendations, some of which are listed below:

Somehow I get the occasional feeling that my output lacked organization and discipline. Take this class for example, should those init logic really be crammed inside viewDidLoad? And certainly there must be a way to organize initViews into smaller, more manageable chunks? A coding convention I began to follow in the past month, introduced by @samgrossberg and @kompfner, turned out to be a great help.

While yet to be convinced about avoiding NIBs and using AutolayoutShorthand over VFL, code written to this convention does *read* much better. At first glance, the nitty gritty suggestions in the document border on OCD (case in point – import statements sorted alphabetically, really?), but the up side is, while reading through a project’s worth of code written in this style, you find yourself getting into the gist of the code much faster as your brain gets quickly accustomed to the pattern. This consistency surely does have great productivity yields down the road and makes it worth the effort during coding.

I’ll put up a before and after comparison of code written in my old style and this new one to illustrate the difference. Meanwhile, do take a moment to read through the convention below. It’s available as a public gist on

Do you have a favorite Objective-C coding convention? Much appreciated if you could share them here or via @kenshin03 on twitter.

One thought on “iOS Coding Conventions

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s