Quick Look Debugging with UIView
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.
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.
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:
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: