More Hello Cocoa!

This is the second iteration of a Hello World Application in Cocoa, enhanced with a sidebar typical of many Mac applications. Apple say “If you’re new to OS X app development, your first step is to become an OS X user yourself” and this is reflected in my approach to learning Cocoa User Interface Design, where I have looked to the standard applications included with OS X such as iPhoto for ideas about design. This App Style is referred to as a Library application.

Hello Cocoa 2

This application is structured so that the main window and each view have a separate controller/XIB and communication between controllers occurs in a way that is considered good object oriented design. To achieve this the sidebar must be able to send messages related to selection changes without actually knowing the recipient of these calls. The purpose of this approach is to achieve a design that is decoupled and unit testable.

To achieve this in Objective-C it is necessary to use a Protocol and inject a reference to the main window into the Sidebar. This design is an implementation of the Dependency Inversion Principle as described in SOLID Object Oriented Class Design. The code snippet below shows the implementation for the Sidebar View Controller initialiser accepting an input of type id typed to HWNavigating, which is the protocol to be implemented by the main window and assigning this to a local variable for later use.

- (id)initWithNavigatingManager:(id<HWNavigating>)navigating {    
    self = [super initWithNibName:@"SidebarView" bundle:nil];    
    if (self) {  
        self->navigatingManager = navigating; // Set the Injected Dependency
    return self;


With the continued evolution of OS X, it’s a great time for software developers to start building Cocoa Applications, though even if Apple say that “Objective-C is a simple language with syntax and conventions that are easy to learn—especially if you have experience with other object-oriented languages…” some effort is still required! You can read about the features that Objective-C adds to C to begin the journey along the long and winding road to becoming an accomplished Apple Developer.

The frustrations I’ve found in learning Cocoa would be common to anybody learning a new programming environment and include trying to find approachable resources that are up to date. Reading eBooks has provided a focused way to get started, followed by the WWDC videos for the current and previous years.

Download source (1.7 MB)

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 )

Facebook photo

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

Connecting to %s