A minor but interesting feature introduced to the debugger in Xcode 5.1 is support for Quick Look to display variables. With a variable selected you can either use the small eye icon or use the space bar with the variable selected in the debugger variables view. A Quick Look popup window then shows you the contents graphically in a popup box. The example below is for UIColor class which shows you a small square filled with the color:
Other system classes that are supported include images, views, locations (displayed as a map), strings and attributed strings and URL classes (displayed as a web page).
Implementing Quick Look for Custom Types
Where this gets more interesting is that you can easily support Quick Look in custom types by implementing -debugQuickLookObject and returning one of the supported types. The Apple documentation provides details on the supported types. As an example consider the custom table view cell I used in the Huckleberry project which consists of two formatted UILabel objects:
By default, the Quick Look for a table view cell does not show anything and if you print the description it is also often unhelpful:
A quick first implementation could be to display the text of the two labels by returning an NSString:
What is even better is if we show the attributed strings:
This gives a nice quick way to check the formatting of an attributed string:
Xcode Debugger Quick Look was originally posted 12 Mar 2014 on http://useyourloaf.com. Copyright 2014 Keith Harrison.