Frame geometry macros to improve your UIKit code

I find myself doing more and more dynamic UI layout in iOS apps these days. When elements of a UI need to resize to fit their contents, or move to accommodate other elements, the layout code can get complex and verbose. We’ve developed a set of Objective-C UIKit macros that help make this code more […]

Objective-C Singleton Pattern Updated For Testability

Objective-C Singleton Pattern Updated For Testability

Posted by on Jan 24, 2013 in BDD, iOS, iPad, iPhone, Mac OS X, Software Development, TDD | 11 Comments

At Two Bit Labs we do a fair amount of unit testing. In places where we use singletons we use a variation on the the Objective-C dispatch_once pattern of thread safe singleton creation. This variation supports resetting the singleton or replacing it with a mock object. That way in our unit tests we can do […]

Objective-C Blocks Cheat Sheet

Posted by on Dec 6, 2012 in iOS, iPad, iPhone, Mac OS X | 6 Comments

Blocks are an incredibly powerful addition to Objective-C, introduced in iOS 4. However, their syntax can be maddeningly difficult to remember. Matt Gallagher has an excellent post that breaks down the syntax to help you understand it. If you haven’t read this article, go do it now. Even after working with blocks for a while, […]

Kickstart your apps with the iOS Xcode Starter Project

Kickstart your apps with the iOS Xcode Starter Project

We created the iOS Xcode Starter Project to make it quick and easy to start a new iPhone or iPad app. Our goal was to create a template to save the hours of effort it takes on a new project configuring essential open source libraries, the unit and functional testing environments, analytics, multiple targets, multiple […]

Block initialization for testability and reuse

Block initialization for testability and reuse

Since Apple introduced block support in iOS 4, more and more APIs are moving from delegation to block callbacks. While block callbacks can be declared inline, in most cases you should initialize your block callback in a method that returns the block. This keeps the code that calls an external API succinct, allows you to […]

The reviews are in!

So be honest: What’s your answer to the question “Do you enjoy reading the latest app store reviews for your app?” (a) “Our users are so smart, kind, and thoughtful that I relish the chance to read their pearls of wisdom.” (b) “Unless they’re written on the bottom of a pint glass, no.” (c) “I’d […]

Enable memory warnings in the iOS simulator to catch crash issues

Enable memory warnings in the iOS simulator to catch crash issues

One common crash issue that’s tough to catch during iOS development of UIViewControllers is the unloading and re-loading of views due to memory warnings. The viewDidUnload method ONLY gets called when a memory warning comes in, NOT as part of the regular view lifecycle. During development it’s likely you may never get a memory warning, […]

Use NLC to simulate flaky mobile networks when testing

Use NLC to simulate flaky mobile networks when testing with NLC

Reduce iOS memory utilization by taming NSURLCache

Reduce iOS memory utilization by taming NSURLCache

If your iPhone or iPad app embeds UIWebViews or makes HTTP requests directly with NSURLConnection, it’s important to keep an eye on memory utilization by running it through the profiler occasionally. Web requests can use a lot of memory, and you may find the memory footprint grows and grows the more you use the app. […]

Initializing UIViewControllers

Initializing UIViewControllers

Most code samples that Apple provides for initializing a view controller look something like this: 
MyController *myController = [[MyController alloc] initWithNibName:@"MyView" bundle:nil]; This always felt like a strange pattern to me. And as Ole Begemann recently pointed out, it’s poor encapsulation. Why does the caller specify which .xib file some other controller should use? Isn’t […]