iOS Libraries for Productive Programming

March 1, 2012 Pivotal Labs

To build working iOS apps quickly and painlessly I have often leveraged open source libraries. It’s important to avoid reinventing the wheel every time your app needs to hit the network, use common UI, socially share content, etc. People have listed libraries before (here, here, and here), I wanted to highlight some that lean more towards dev tools than front facing user features.


Cedar, I believe, is the first library to bring BDD-style testing to iOS. Cedar uses blocks to achieve tests that appear similar to natural language requirements, for example:

describe(@"NSString helper functions", ^{
  it(@"should decode a short string", ^{
    expect( [@"TEST" lowercaseString] ).to(equal(@"test"));

I find this more readable and descriptive than the awkward “testStringConvertsTestToLowercaseTest” methods the SenTestingKit framework corners me into. Cedar has a cool UI in the simulator, and it works on the command line making it easy to hook up with Continuous Integration. For mocks and stubs, you can use OCMock.


In iOS development we often have to present a view composed of many images, labels, and input fields at pixel perfect positions. Before DCIntrospect this would mean endless cycles of compiling, running, and tweaking. With DCIntrospect we can debug the position of views and change them at runtime! This is all done quickly and easily with keyboard shortcuts. It’s like Firebug for iOS.


Before AFNetworking, ASI-HTTP-Request was king of the iOS networking libraries. ASI-HTTP-Request had caching, gzip support, and every other feature imaginable. The problem was that the codebase was huge and doing something unsupported by the library was difficult. AFNetwork came along as a simple, lightweight networking library. It brought blocks to network callbacks (ASI now has block support) which greatly simplified the whole problem of keeping state in the controller’s variables.


Aspect oriented programming is a paradigm that never quite achieved the widespread usage it promised. Nonetheless, it has interesting properties in Objective-C. There are still some holes in modern OOP that force us to write boilerplate code. For example, let’s say we want to release all active network connections on the deallocation of the view controller who owns them. To do this we could copy and paste code to cancel them in the dealloc method, but that would be tedious and prone to error. We could try to write a common base class that handles this,
but this won’t work if we want to use other view controller subclasses (UITableViewController for example). AspectObjectiveC allows us to create an Advice. This Advice object can run a function before or after any other method call of a given class. With an Advice object we can make a function that cleans up running network connections before the UIViewController deallocs.


MAObjCRuntime is a Objective-C wrapper for the Objective-C runtime. This allows us to do things at runtime like swap a method for another method in an object or add ivars to a class. Reflection is one of the features that separates Objective-C from C++, but seldom do we take advantage of this feature. Perhaps the reason for this is
that the objective-c runtime API is confusing and difficult to use. MAObjCRuntime simplifies it. Take a look at this example of the Objective-C’s runtime library being used to make any object comply with NSCoding. It’s hard to read and understand, but extremely useful. Hopefully this wrapper will enable more people to experiment with reflection.

Here are more sites you can use to find useful libraries:

About the Author


Make Jasmine run at (near) full-speed in a background tab
Make Jasmine run at (near) full-speed in a background tab

Jasmine environments have a default updateInterval value of 250 that determines how often, in milliseconds,...

7 Tools in an Advanced Android Development Workflow
7 Tools in an Advanced Android Development Workflow

Understanding your development tools allow you to spend less time writing boilerplate code and solving the ...