Question

Let's say I have a UIImage that I'm setting for a UIButton. I want to look at it in Quicklook. But oh no:

enter image description here

There's no way for me to quick look debug what the image is.

But I could do something from LLDB to get the image, like [getAppButton imageForState:0] (well, I could if it wasn't for the undoManager bit but that's not neither here nor there), but is there a way to quicklook that?

Was it helpful?

Solution

I'm not sure when this was introduced, but in Xcode 6.3.2 you can right click on the left panel in the debug area and choose Add Expression.... This pops up a text field where you can put in any arbitrary LLDB expression. After entering it, you can invoke quick look on the expression just like any other local variable in that pane.

Quicklook

You can also reference variables defined in LLDB, for example if you were to type:

(lldb) e UIImage *$img = [button imageForState:0]

You can then reference that $img as the expression in the left pane.

OTHER TIPS

I don't think it is possible. At least I could not find a suitable command in Apple's documentation.

The only way I can think of, is modifying your code to assign the image in a UIImage variable and quick look that...

In Xcode 5.1, you can now add a method:

- (id)debugQuickLookObject

to any object and the returned value will be used for QuickLook. So in your case, you could subclass your button, and return your image.

You can now do that using chisel's visualize lldb command. It's very straightforward to set up, and it's a debugger super-power that's particularly handy if you work with images a lot.

Once you've installed chisel, update your ~/.lldbinit file and restart XCode. Then create a new breakpoint and add an action that uses the command to inspect an UIImage1.

lldb breakpoint settings in XCode

Under the hood, the new python based lldb command writes the image buffer into a timestamp-based PNG file under /tmp/xcode_debug_images and then call system command open to use the default app to open up the image.

Keep in mind that lldb holds a strong reference to the data. So during your debug session, your app might appear to leak RAM. Remember to turn the breakpoint off when you are done.

Also, if you have a lot of images, you may not want to open them up all in Preview, which will freeze itself with more than 100 images. Comment this line off, and you should be fine: https://github.com/facebook/chisel/blob/main/commands/FBVisualizationCommands.py#L60

On my M1 mac, the file is installed into /usr/local/opt/chisel/libexec/commands/FBVisualizationCommands.py

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top