O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Make DieView a Drag Destination

There are several parts to being a drag destination. First, you need to declare your view a destination for the dragging of certain types. NSView has a method for this purpose:

f​u​n​c​ ​r​e​g​i​s​t​e​r​F​o​r​D​r​a​g​g​e​d​T​y​p​e​s​(​n​e​w​T​y​p​e​s​:​ ​[​A​n​y​O​b​j​e​c​t​]​)​

You typically call this method in your initWithFrame: method.

Then you need to implement six methods. (Yes, six!) All six methods have the same argument: an object that conforms to the NSDraggingInfo protocol. That object provides the dragging pasteboard. The six methods are invoked as follows:

  1. As the image is dragged into the destination, the destination is sent a draggingEntered(_:) message. Often, the destination ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required