Xcode 5.1 was released the other day and with it we got a bunch of new features including Quick Look Debugging for custom objects. I covered this briefly on NSScreencast episode 111.

As long as you can distill your object into one of the supported types, you can provide a visualization for your own objects.

quick look of a CLLocation

No matter that the class is PhoneNumber, to demonstrate the feature I just implemented the method by returning a CLLocation *.

UIView is also supported, however it seems to be limited to UIViewController’s view property.

quick look of a custom view

You might notice that if you just have a variable of a UIView that you can’t take advantage of this. Instead, you’ll get this message:

quick look view failure

My suspicion is that this is because the - debugQuickLookObject method is implemented on a category method that is included by UIViewController. I’m not entirely sure if this is the case, but we can create our own category method to provide the same behavior.

#import "UIView+DebugObject.h"

@implementation UIView (DebugObject)

- (id)debugQuickLookObject {
    UIGraphicsBeginImageContext(self.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.layer renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

@end

Once that’s done, I just include the category method header in my view controller, and quick look debugging of view variables now works:

quick look of a view variable