Objective-C
Instance Variables in the Implementation File
Within Xcode, if you set the compiler option to Apple LLVM compiler 2.1 (or greater), you can move your instance variable declarations from the interface file to the implementation file. For example, here is a traditional interface definition with instance variables declared: @interface SandboxViewController : UIViewController <uitextfielddelegate> { UITextField *username; UIButton *testButton; UILabel *label; } [...]
Objective-C Comment Styles
A few weeks ago I wrote about Objective-C Indentation Styles. A reader (thanks Joe) commented and suggested a similar post that covered comment formats. That blog post follows… Interface File Comments When I create an interface file, here is the basic layout of my comments: /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * AboutViewController.h * * Created by John on 6/10/11. [...]
Objective-C Indentation Styles
Discussions with developers about their preferred indentation style often seems to stir the same passion as one’s preference for beer, wine or cocktails. This post isn’t as much a tip or trick, as it is an opportunity for developers to share their variations and preferences when it comes to indenting code. Let me give you [...]
Introduction to Blocks in Objective-C – Part 2
In the first post on blocks, Introduction to Blocks in Objective-C – Part 1, I covered the basics for creating block variables, working with __block modifier and using typedef to define blocks. In this post I will show how you can pass a block as a parameter, use enumeration with blocks, as well as take [...]
Introduction to Blocks in Objective-C – Part 1
Beginning with iOS 4.0, Apple introduced blocks, which look and operate much like C functions. However, blocks offer many interesting capabilities beyond functions as you know and love them today. A block is really nothing more than a chunk of code. What makes them unique is that a block can be executed inline as well [...]
Using the @class Directive
The @class directive often seems to be a point of confusion. Let me try and provide a little insight. The @class directive sets up a forward reference to another class. For example, in the code below the reference to @class HomeBrewRecipes informs the compiler that HomeBrewRecipes is indeed a class, so when the compiler gets [...]
The Basics of Protocols and Delegates
Apple offers a good overview of working with protocols in their Objective-C Programming Reference. However, sometimes a simple working example can go a long ways… Introduction Protocols can be helpful in a number of scenarios, a common usage is to define methods that are to be implemented by other classes. A familiar example is when [...]
Fast Enumeration on the iPhone
With the introduction of Objective-C 2.0, you can now iterate through collections (arrays, etc) with ease using a language feature known as Fast Enumeration. This enumeration is both faster than using NSEnumerator and is also much more concise as it relates to the syntax, resulting in code that is easier on the eyes.
Specifying Simulator Only Code
There are times when you need to write code that is only applicable when working with the simulator. As an example, I was recently working with an application that required the user to take a picture with their iPhone. Once the picture was taken the application was to show the image to the user, at [...]


