Cocoa OSX: How can I make an image draggable

I have a panel with an image on it, and I want to make it so that you can copy a file (not the image,the image is only going to server as an icon for the file) into a folder by “dragging” the image outside of the application and into any other application that accepts files being dragged into it (ex. Finder). How can I do this?

I implemented the NSDraggingSource protocol, but I’m not sure how to make the image draggable. It is currently inside of an ImageView, which is inside of an ImageViewCell.

  • How do I get exception details in XCode 4.6?
  • Select tableview row programmatically
  • iOS Tab Bar icons keep getting larger
  • Can't capture masks within view layer
  • How To Draw line on touch event?
  • How to compare two NSDates: Which is more recent?
  • Here is the protocol I implemented:

    #import "DragNDropView.h"
    -(NSDragOperation)draggingSession:(NSDraggingSession *)session
    sourceOperationMaskForDraggingContext: (NSDraggingContext) context{
        case NSDraggingContextOutsideApplication:
          return NSDragOperationCopy;
          return NSDragOperationNone;
    -(void) draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint) screenPoint{
       NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
       NSPaseBoardItem *contents = [[NSPasteboardItem alloc]
                                    inithWithPasteboardPreopertyList:SDKFileName ofType:NSFileContentsPboardType];
       [pboard writeObjects[NSArray arrayWithObjects:contents, nil]];
      SDKFileName = @"example.example";
      [super drawRect:dirtyRect];

    Solutions Collect From Internet About “Cocoa OSX: How can I make an image draggable”

    I added the method - (id)initWithCoder(NSCode *)coder and I also added
    - (BOOL)acceptesFirstMouse:(NSEvent *)event { return YES; }