This Week on Github: iPhone Development

For many software developers, Apple’s iPhone prints money. For other developers, it’s a vexing mess. If you’re just getting started with iPhone coding, GitHub can help. A lot.

For many software developers, Apple’s iPhone prints money. For other developers, it’s a vexing mess. As you waltz into the depths of Objective C, Cocoa, and the host of iPhone software development tools, it can be difficult to find sufficient official documentation and near impossible to find examples of many techniques and libraries.

Fortunately, a good number of hackers have created excellent open source projects to correct the shortfall. This column points out a few helpful iPhone coding aids that call Github home.

Getting Started

If you’re just getting started with iPhone development, check out the free iPhone coding class offered by the prestigious Stanford University. The class lectures are available on iTunes—search for“CS193P”—or click the iTunes link from the class’s home page at http://www.stanford.edu/class/cs193p). The instruction is valuable and teaches the ins and outs of developing for the iPhone, but each class’s assignment is where the real learning takes place.

If you get stuck on any particular assignment, you can find solutions on Github. The most complete set lives at http://github.com/iamdanw/stanford-iphone, but there are also solutions available in http://github.com/olly/cs193p, and http://github.com/iamdanw/stanford-iphone.

Paging Dr. Nic, Paging Dc. Nic

Dr. Nic Williams or &ldquoDr. Nic&rdquo, well-known in the Ruby world, has created a few useful tools for iPhone developers. The first of these, rbiphonetest, lets you write iPhone unit tests in Ruby, saving you from the horrors of STAssertTrue and its ilk.

rbiphonetest uses RubyCocoa to bridge between Ruby and Objective-C. So to test a Downloader class in the WebDownloader bundle, run rbiphonetest in the project directory, and write some code like this:

require 'WebDownloader.bundle’
OSX::ns_import :Downloader

class TestDownloader < Test::Unit::TestCase
  def test_downloads_a_file
    # Your test code here...

That’s much cleaner!

If you’re interested in finding out more about testing your iPhone app with Ruby, watch Dr. Nic’s video tutorial on the matter at http://www.vimeo.com/1262916 and checkout the code from http://github.com/drnic/rbiphonetest.

If you’re writing a lot of Objective-C and find yourself annoyed by some of XCode’s quirks (such as how it handles documents and windows), you can skip XCode and use a real editor, such as TextMate. Dr. Nic has also published a TextMate bundle for editing Objective-C with excellent snippets and syntax highlighting. You can grab the bundle at http://github.com/drnic/objective-c-iphone-tmbundle.

Getting Resourceful

Cocoa’s networking libraries are fantastic when compared with many of the other available options for C and C-like languages (Boost Sockets are icky!). So when someone takes those great libraries and then puts some really nice abstractions on top of them, you know you’re looking at a recipe for pleasantness.

The guys over at Y|Factorial have created a clone of Rails’ RESTful remote object framework ActiveResource for Objective-C called ObjectiveResource. This library lets you easily talk to RESTful web services.

For example, if you want your iPhone application to work with a remote resource for a blog post., you could do something like the following:

@interface BlogPost : NSObject {
  NSString *title;
  NSString *body;

@property (nonatomic , retain) NSString *title;
@property (nonatomic , retain) NSString *body;

#import “ObjectiveResourceConfig.h”

[ObjectiveResourceConfig setSite:@"http://yourblog.com"];
NSArray *posts = [BlogPost findAllRemote];

After the last line, the posts variable has an array of BlogPost objects populated with data fetched from your remote REST web service. That’s a bit easier than pulling those objects from the server, parsing the XML or JSON, and feeding that data into an Objective-C object by hand.

The ObjectiveResource developers provide an example Rails application as the back-end, but you can easily build your remote web services in any language. Check out the code at http://github.com/yfactorial/objectiveresource and the companion site at http://iphoneonrails.com/.

The Y|Factorial guys also offer some other interesting libraries that have been extracted from ObjectiveResource, such as ObjectiveSupport (http://github.com/yfactorial/objectivesupport), which provides a number of utility classes and methods (mostly for serialization), and ObjectiveSync (http://github.com/yfactorial/objectivesync), an abstraction of “the various synchronization policies used when linking a remote iPhone app to a supporting backend web service.”

A Potpourri of Good Code

If you’re just searching for some little snippets or good examples of Objective-C code, there are many “potpourri” repositories around Github. Here are a few that I find useful:

  • Buzz Andersen provides a repository of interesting code at http://github.com/ldandersen/scifihifi-iphone. Check out the snippets for security that work with the iPhone’s keychain (the facility to persist usernames and passwords in a safe way) and the SFHFActivityIndicatingCell class within UI, which provides a nice activity indicator for use in TableViews.
  • The three20 project from Joe Hewitt (http://github.com/joehewitt/three20) is a very polished library of user interface components and utility classes. It includes a really slick Photo Viewer component, a class to emulate Mail.app’s message composer, an image view for loading images from the web, a disk cache for HTTP requests, and more. If you’re looking for a great example of good Objective-C code (especially how to create your own custom views), this repository is a gold mine.
  • Mike Clark, author of the MacRuby screencast available from the Pragmatic Programmers, has a repository of iPhone “goodies” at http://github.com/clarkware/iphone-goodies. These largely consist of enhancements to existing classes, such as the extensions to UIDevice to get the IP address, phone number, and available memory of the current device), and one killer addition: tests. This repository is a great way to learn how to unit test Objective-C code in a very simple way.

In this post, I’ve only pointed out a very small part of the great iPhone and Objective-C resources out there on Github. I plan on covering even more of these resources in the future, so if you’ve found something useful, feel free to point it out to me via Github at jeremymcanally or on Twitter at @jm.

Comments on "This Week on Github: iPhone Development"


The following github member has assignment 3 for cs193p Iphone development. The hello polly app at URL http://github.com/paulgribble/


I have also been doing the assignments and they are available on my github page. I hope to have Presence 1 done this week.


Excellent beat ! I wish to apprentice while you amend your site, how could i subscribe for a weblog site? The account aided me a appropriate deal. I have been a little bit familiar of this your broadcast offered vivid transparent concept

im with jo8b#&h230;hynreds and elect cars are a fad,,,sop to the greenies,,,there soon will be shortages in battery making materials…. real answer will be natural gas power and coal gasification to run small 3/4 cylinder engines running a generator to power an electrict motor

“I’ve learn several excellent stuff here. Definitely worth bookmarking for revisiting. I wonder how much attempt you put to make one of these wonderful informative site.”

jgxjzk lmceumvzyisx, [url=http://osmdndkcvdnn.com/]osmdndkcvdnn[/url], [link=http://myencjmpvjov.com/]myencjmpvjov[/link], http://dmpelemkixvv.com/

Keep up the excellent work, I read few blog posts on this website and I believe that your web blog is really interesting and holds sets of great info .

Leave a Reply