Not Cuckoo for CocoaPods

Posted by on Dec 10, 2013 in iOS | 7 Comments

The projects we work on generally have have dependencies on one or more (often several) open source projects, including our own libraries. We’ve always managed those dependencies using git submodules. As submodules have some quirks, a few projects have cropped up trying to make dependency management easier. The one that’s gained the most traction is […]

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, […]

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 […]

Empty or incorrect URL with webViewDidStartLoad

Posted by on Aug 9, 2011 in iOS, iPad, iPhone, Mobile Applications | No Comments

If you’re using a UIWebView in your iPhone or iPad app and you want to execute some code when a page starts loading you’ll likely turn to the webViewDidStartLoad: method in UIWebViewDelegate. However, you may have surprisingly unpredictable results. For example, the following code won’t work as expected: – (void)webViewDidStartLoad:(UIWebView *)webView {     if […]

Some great UIColor resources

Posted by on Mar 6, 2011 in code | 3 Comments

I’ve recently come across some nice resources for working with UIColors. Developer Color Picker Developer Color Picker is a color picker built for, you guessed it, Objective-C developers. Just install it in ~/Library/ColorPickers and it will appear in any application when you pull up the color picker. You can switch between RGB and HSB sliders […]

Mocking singletons with OCMock

Posted by on Feb 28, 2011 in code | 20 Comments

Although Graham Lee might not approve, I occasionally use the singleton pattern, particularly for managing access to my data models. Singletons in Cocoa are accessed using the following convention: static UserModelManager *sharedManager = nil; +(UserModelManager *)sharedManager {     if (sharedManager == nil) {         sharedManager = [[super allocWithZone:NULL] init];     […]

Declarative logging in Objective-C

Posted by on Jan 12, 2011 in code | One Comment

I’m currently working on a project with a requirement to log various events using Google Analytics. I created a UsageLogger service to encapsulate all the GA logic and make it easy to turn it off or replace it with another analytics solution. But I didn’t want to have logging methods sprinkled throughout the code, and […]

Using Objective-C blocks to log Core Data entities

Posted by on Nov 17, 2010 in code | No Comments

Usually when I want to log the Core Data entities returned by a query in a particular context, I just passed the object to a log statement, like so: 
NSLog(@"Query returned %@", theCoreDataObject); This works OK when you just have one object to log, but if you want to log the whole array of entities, […]