Ok, Here's the code I'm using :
if let image = NSImage(pasteboard: pasteboard){
//..
}
And I have 3 ways where images come into the app:
- If the image is dragged to the window, and using the dragging pasteboard, the image is correct.
- If the image is copied in browser, "Copy Image".. and using NSPasteboard.general().. The image is pasted correctly.
- If the image is copied in Finder, right click -> Copy "image-name.jpg". then the pasted image is NOT correct. Instead I get the icon for JPEG file type.
I tried other methods, including apple's snippet (same result, I get icon instead of the image itself) :
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *classArray = [NSArray arrayWithObject:[NSImage class]];
NSDictionary *options = [NSDictionary dictionary];
BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
if (ok) {
NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
NSImage *image = [objectsToPaste objectAtIndex:0];
[imageView setImage:image];
}