2

Is there a feature in Xcode that allow you to inspect NSImage references while debugging?

Similar to how webkit inspector let you inspect image references in webpages.

Failing that, what's the easiest way to debug while working with NSIMages?

webkit inspector

pkamb
  • 33,281
  • 23
  • 160
  • 191
Tony
  • 36,591
  • 10
  • 48
  • 83
  • What exactly are you trying to debug? i.e. What is the problem you're having that you'd like help debugging? – Andrew Madsen Dec 30 '11 at 21:56
  • Possible duplicate of: [Xcode debugging - displaying images](https://stackoverflow.com/questions/2780793/xcode-debugging-displaying-images) – pkamb Dec 04 '19 at 11:40

2 Answers2

4

As of Xcode 5 you can use QuickLook to inspect an NSImage or UIImage, just select it in the Variables View and click the Eye icon (or press space).

See also: Xcode debugging - displaying images

Community
  • 1
  • 1
MagerValp
  • 2,922
  • 1
  • 24
  • 27
4

UPDATE: with Xcode 5 and newer take a look at the answer by MagerValp. it looks like you can preview a image right in Xcode.


No, as far as i know there is no such feature in Xcode. If your application creates or manipulates images and you would like to see the visual representation of the data behind a reference to NSImage, you could dump the image to the filesystem.

Just create a category, which adds -(void)dump to NSImage like this:

@interface NSImage (Dump)
- (void)dump;
@end

@implementation NSImage (Dump)
- (void)dump {
    NSBitmapImageRep *imageRep = [[self representations] objectAtIndex: 0];
    NSData *data = [imageRep representationUsingType: NSPNGFileType properties: nil];
    [data writeToFile: @"/tmp/image.png" atomically: NO];
}

@end

Now you can set a breakpoint somewhere in your code and call the method dump on your reference of NSImage by typing following in the command line of the debugger:

po [image dump]

the only change in your source code is the import for the category.

Yevgeniy
  • 2,614
  • 1
  • 19
  • 26
  • Rather than assuming that the image's first representation is an NSBitmapImageRep, it'd be better to send the image `TIFFRepresentation` and write that to a .tiff file. Also, writing to /tmp won't work if the application is running in a sandbox. – Peter Hosey Dec 31 '11 at 05:34
  • @PeterHosey and i would not dump every image to the same path either, but i do in the example to keep it simple. – Yevgeniy Dec 31 '11 at 08:27