Category Archives: Patterns guides and best practices

Keeping ViewController files small

If you’re working on a complex iOS app, it’s very easy to create a UIViewController subclass with a huge amount of code. One of the many code guidelines I learned at Google was the simple idea of keeping functions and files small. For example, I would recommend trying to keep the vast majority of your […]

Printing in iOS

This post gives a quick introduction on how to print in iOS 4.2+. There are multiple ways to interact with AirPrint, but for brevity I’ll focus on printing a single PDF document.  This actually covers a lot of cases, since anything you can draw in Quartz can be drawn into a piece of PDF data […]

Code formatting

In this post, I’ll give a quick overview on choosing a personal coding style, and present a way to auto-format code in bulk. If you take your code seriously, you probably have a code style that you consistently use. For example, maybe you always use braces with every if clause, or you use underscores in […]

Custom objects as NSDictionary keys

This post describes what is needed for any class to work as a key of NSDictionary or NSMutableDictionary. The only thing that is really required is that your class adopt the NSCopying protocol.  That’s because every key is copied before being added to the dictionary.  I mention why this design decision was probably made below. […]

let it be

This post explains one of my favorite NSObject categories – one that is extremely universal and handy for shorter and, in my opinion, more memory-manageable code.  (Code below.) Edit: Commenter David found a bug in this implementation. Check out the fixed version here; the new source files are listed at the bottom of that post. (The […]

Introducing the Default Delegate design pattern

I recently posted an overview of callback mechanisms in Objective-C, including the pros and cons of delegates versus target/action pairs; in this post I’ll introduce a new design pattern that combines many of the benefits of both of these approaches into a single technique. If you’re building a class to be reused many times, it […]