Xcode debugging - displaying images - xcode

I love using the Xcode debugger. You can take a look at a variable's value and even change it.
But can I somehow DISPLAY the image that is referenced by an image variable? I know I can see its raw bytes, but it would be much more human-friendly to display a window with its contents.
Xcode might not support this. Maybe there is an external tool that would help display images?

Use Quick Look to inspect images in the Xcode debugger.
Select an NSImage or UIImage in the debugger, then click the Quick Look "eye" icon.
Like other areas of OS X, you can also use spacebar to Quick Look!
Quick Look in the debugger can also be implemented for your own classes:
Enabling Quick Look for Custom Types
The variables Quick Look feature in the Xcode debugger allows you to obtain a quick visual assessment of the state of an object variable through a graphical rendering, displayed in a popover window either in the debugger variables view or in place in your source code.
This chapter describes how you implement a Quick Look method for your custom class types so that object variables of those types can also be rendered visually in the Quick Look popover window.

If you like to work with the lldb console, use chisel command "visualize"
tip:
after the installation, you can set a conditional breakpoint after setting the UIImage with the action:
"visualize myUIImageToShowWithQuickLook"
this will show you the image automatically when the debugger stops.

EDIT:
As of Xcode 5, the debugger can show you the visual representation of UIImage/CGImageRef variables!
Xcode itself can't do it. I don't know about external tools.
What i'm doing to test images while debugging is to convert that raw data into an image-file format, like .png, and then saving it somewhere, and then i'm opening the image with any image viewing tool.
I have a piece of code for that purpose, which look basically like that:
NSData *imageData = UIImagePNGRepresentation(self.myUIImage);
[imageData writeToURL:desktopURL atomically:YES];
And i'm just copy-pasting this code where i want to see content of an image on the run.
Make sure to get rid of this code as soon as possible due to the high-cost of the conversion of UIImage to NSData

Edit for Xcode 5: Now when you hover over an image variable name, there is an "eye" icon on the right. Just click it to see the current image!
NOTE: sometimes this fails in Xcode, even if the image is correct. If this happens, OR if you don't have a UIImage variable (e.g. it's a property of another object, you can still use the older answer:
Older answer: Starting with Avraham's answer, I tried a few experiments for displaying an iOS image from lldb without having to recompile or add it to a view. I finally came up with:
e [UIImagePNGRepresentation(myImage) writeToFile:#"/Users/<userName>/Desktop/myImage.png" atomically:NO];
I keep this string in a text editor and paste it when I need it. This stores the current image I'm interested in (in this case, "myImage") to a PNG file on the Desktop. Then I can just open this file with Preview.
If you're working on an iOS device, then you can use
e [UIImagePNGRepresentation(myImage) writeToFile:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingString:#"/myImage.png"] atomically:NO];
Then you can use the Finder; select your device; "Files"; then your dev app, and copy the image to your Desktop to view it.

What if you can't get to the image via the variables view?
Echoing what #pkamb said - you can use the variables view to quick look at an image. But what if you can't get to the image?
for example I have an image at (contentViewController.view.subviews[0].subviews[1] as? UIImageView).image
but if I try to expand contentViewController in the variable view it doesn't expose my subviews
what you can do is right click, add an expression, and then you can see it!

Click the eye icon when hovering over a variable in Xcode:

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's a GDB command which will display several useful informations about the object passed, in your case the image.

Related

How to show a self-defined view as SCIM.app in the System preference - Keyboard - Input Sources

I am trying to intergrate our input method to the 10.10.3
And I found it's not easy to act like SCIM.app as the pic shows
I opened the activity monitor to see what file it opened (the SCIM.app was not running) As you can see in the following images:
The left shows the file list opened by System preference, and the right shows after I click the pinyin-chinese, the file list opened.
So I guess the little view was created by CoreChinese.framework. Since it was in /System/Library/PrivateFramework , It seems impossible for me to show this view as SCIM.app by a normal way.
I turned to nm and hopper disassembler...But I found it a long way to go
I guess you guys may encounter the same question, maybe you can help me.
Yes, I came across the same problems with yours.
1.It's easy to know that the view you saw, is provided by two part, the upper keyboard is a webview, which takes data in /System/Library/Input Methods/SCIM.app/Contents/Resources/*.keylayout, and finally shown by IntlKeyboard.prePane located in resources directory of Keyboard.prePane. and also you can find the actual html and pics, and 2nd part is a self-defined view provided by Preferences.prefPane.
2.Then 2nd part is to show the view you saw under the keyboard. as SCIM.app does, a file named Preferences.prefPane(must in the Resources directory of SCIM.app) was taken by IntlKeyboard.prePane.

How to save Xcode Window Layout and Size

I've got my workspace windows set up like this:
Then I Navigate away from my story board to replace the left window with some code so i Can compare two code documents like this:
When I navigate back to my storyboard, it resets the document outline column to this:
How the frak do I configure window sizing presets? Coming from an Adobe background I'm used to having a preference somewhere that allows me to save interface layouts and sizing presets. The closest thing I can find is "behaviors", but this doesn't seem to control the sizing of columns and windows.
Seems like the best way to handle this is by using "Tabs"
I found this very helpful blog post.

What is the flag to show the nesting of views in a Mac app?

I have just spet the last few hours trying to find the flag to use in Terminal to launch an app with the colored outlines around the various view elements to show how they are nested. I know that Matt Gemmell covered it during the Cocoa Face Off session of NSConference 2009 (at about the 13minute mark in the video). Unfortunately I can't actually read what he types and he doesn't speak the exact command. I know it has to be in the Apple docs somewhere but the search system is currently not being of any use. It looks like her just adds -showAllViews YES to the end of the command to open TextEdit but that command has no effect in 10.6.6. I have also tried every other capitalization I can think of as well as using view instead of views. Every command opens TextEdit just fine but doesn't show the colored outlines.
Use -NSShowAllDrawing and -NSShowAllDrawingColor:
/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSShowAllDrawing 200 -NSShowAllDrawingColor cycle
-NSShowAllDrawing sets the delay between drawing commands (allowing you enough time to see the drawing update)
-NSShowAllDrawingColor sets the fill colour for the regions with pending drawing operations (see class methods on for NSColor for valid values, or pass it "cycle" to loop through all available colours).

What is the name of this Mac OS X control?

Does this control have a name? Or is it just a bunch of simple controls merged together? If so, what controls are they?
http://img8.imageshack.us/img8/3002/picture2xrb.png
It looks like an NSTableView with an a custom cell type and no column header. Have a look at the documentation for NSTableView's tableView:dataCellForTableColumn:row:. For columns which have the same type for all rows you may also set the cell class in interface builder.
I doubt the search box is part of the same control.
You could open the Application's Nib file to see what is in there. Look inside the application bundle. If the application is called Example then you should be able to find the Nib at Example.app/Contents/Resources/English.lproj/MainMenu.nib.
The best tool for investigating this is fscript, specifically FScriptAnywhere which will let you determine the class and much other information about any visual element of any Cocoa program (and do a lot of other interesting things with Cocoa programs).
In addition to what toholio said, an easy way to get the look and feel of the bottom button bar is with BWToolkit.

Which function does Leopard's Finder get the preview icons with the watermark on them?

I already took a look at GetIconRefFromFileInfo() and QLThumbnailImageCreate() but they just doesn't seem to be similar with what I see from the finder, which is a square icon with watermarks on it, e.g. if the file is RTF, it has this greyish watermark below that says RTF or RTFD or PDF...
Please help me out on this. Thanks. If the question is still unclear, please feel free to comment.
From MacScripter:
This is a category on NSImage which
lets you get an image containing a
Quick Look preview of the content of a
given file. If no Quick Look preview
is available, it will instead return
the file's Finder icon (this is what
the Quick Look panel does). It
consists of only one method:
+ (NSImage *) imageWithPreviewOfFileAtPath: (NSString*) path ofSize: (NSSize) size asIcon: (BOOL) icon

Resources