Xcode Debugging - Image Display

I like to use the Xcode debugger. You can take a look at the value of a variable and even change it.

But can I somehow display the image referenced by the image variable? I know that I can see its raw bytes, but it would be much more convenient for a person to display a window with its contents.

Xcode may not support this. Maybe there is an external tool that will help display images?

+70
debugging xcode
May 6 '10 at 11:49
source share
6 answers

Use Quick Look to check images in the Xcode debugger.

Select NSImage or UIImage in the debugger, then click the View icon Quick View.

"eye" icon in Xcode debugger toolbar

As in other areas of OS X, you can also use the spacebar for quick browsing!

Viewing a UIImage in the Xcode debugger via Quick Look

Quick lookups in the debugger can also be implemented for your own classes:

Enabling quick view of custom types

The function for quick viewing of variables in the Xcode debugger allows you to get a quick visual assessment of the state of a variable in an object using the graphic rendering displayed in a pop-up window either in the debugger variables view or in place in your source code.

This chapter describes how to implement the Quick Look method for custom class types so that object variables of these types can also be visually displayed in the Quick Look pop-up window.

+209
Oct 30 '13 at 2:14
source share
β€” -

EDIT:

Starting with Xcode 5, the debugger can show you a visual representation of the UIImage / CGImageRef variables!

Xcode itself cannot do this. I do not know about external tools.

What I do to check images during debugging is to convert this raw data to an image file format, such as .png, and then save it somewhere, and then open the image using any image viewer.

I have a piece of code for this purpose that looks basically like this:

 NSData *imageData = UIImagePNGRepresentation(self.myUIImage); [imageData writeToURL:desktopURL atomically:YES]; 

And I just copy this code where I want to see the contents of the image on the go.

Be sure to get rid of this code as quickly as possible due to the high cost of converting UIImage to NSData

+16
Feb 20 2018-11-21T00:
source share

Edit for Xcode 5:

Now when you hover over the name of the image variable, the eye icon will be on the right. Just click on it to see the current image! If you don't have a UIImage variable (for example, this is a property of another object, you can still use the older answer:

Old answer: old question, but I was looking for an answer. Starting with Abraham's answer, I tried several experiments to display an iOS image with lldb without having to recompile or add it to the view. I finally came up with:

 po [UIImagePNGRepresentation(watchImage) writeToFile:@"/Users/<userName>/Desktop/watchImage.png" atomically:NO]; 

I store this line in a text editor and paste it when I need it. This saves the current image of interest to me (in this case "watchImage") in a PNG file on the desktop. Then I can simply open this file with a preview.

+13
Aug 31 '13 at 1:40
source share

If you like working with the lldb console, use the chisel render command

Tip:

after installation, you can set a conditional breakpoint after installing UIImage with the action: "render myUIImageToShowWithQuickLook"

enter image description here

this will show you the image automatically when the debugger stops.

+11
Aug 19 '15 at 8:22
source share

What if you can’t get to the image through the presentation of variables?

Repeating what @pkamb said, you can use the variable view to quickly view the image. But what if you cannot get to the image?

for example, I have an image in (contentViewController.view.subviews[0].subviews[1] as? UIImageView).image

but if I try to expand the contentViewController in a variable view, this does not reveal my subviews

enter image description here

what you can do is right-click, add an expression, and then you can see it!

enter image description here

enter image description here

enter image description here

+1
Oct 31 '18 at 23:49
source share

You can put a breakpoint in the line of your image, and then in the debugger just write:

 po your_UIImage_object 

po stands for print object , it is a GDB command that will display some useful information about the passed object, in your case an image.

-5
Aug 14 '12 at 15:48
source share



All Articles