Category Archives: clean coding

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 […]

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 […]

Memory Warnings

This post gives a quick intro to dealing with memory warnings in iOS. I have to admit, I’ve avoided this subject for a looong time while learning iOS.  The first word says “these bugs will be incredibly annoying” and the second word says “you can just ignore these.”  Or rather, that’s what the back of […]

Handling rotations in UIViewController

In this post I’ll give a few general tips for handling device rotations at the UIViewController level.  These tips are for code using iOS (formerly known as iPhone OS) 3.0 or later, which includes all iPad code. 1.  In willAnimateRotationToInterfaceOrientation:duration:, size and position the view for the new orientation. This sounds obvious and easy, but there […]

Memory management guidelines

In this post, I’ll outline four simple rules for memory management in Objective-C. The Apple docs have already established basic guidelines for object ownership, following the fundamental idea that if you own an object, then you’re responsible for releasing it. This post goes a step further with tips for when and where ownership can be […]

Simplified popovers

In this post, I’ll present a microclass that can give you simplified popover ( UIPopoverController ) handling in many cases, including automatic rotation updates. Links to code below. What PopoverHelper does Normally, this is how you need to work with a popover: Set up the content view controller that will appear in the popover. Alloc […]

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 […]