General Questions on the Chapter


I have reached the end of this chapter and some things just are not clicking for me.

First, at the end of the chapter, the Operation Mask, seems to work by observation of the logging, but I don’t detect any change to the cursor when using modifier keys. The cursor always stays as the “+” symbol.

Next, when dragging from the panel to the trash can on the dock, the letter does of course go away, but the trash can does not reflect anything being added to it nor is there anything in it once dropped. Is this the expected result?

Finally. I invoked the challenge back at the end of Chapter 20 (ref adding bold and italic) and left the code in place. Why is it, when dragging from the first panel to the second, the bold and/or italic does not copy over, but the shading does? I added the bolding and/or italic in the same method (-prepareAttributes) as the shading we did from the book. I realize that they are only traits attached to the font, but still they are part of the font attribute.


The reason the cursor does not change is because draggingUpdated: is written to always return NSDragOperationCopy or NSDragOperationNone. So the drag destination is not allowing the drag operation to consider any of those other proposed operation types. You can try changing it to return ‘op’ and you will be able to see the cursor change between move and copy.

Dragging to the trash: it is normal not to see any reaction from the trash can. As the drag source you can respond to a delete operation and do something like the “poof” animation in draggedImage:endedAt:operation:. NSShowAnimationEffect() can help with this. For an example, see here. In that specific case an item being dragged outside of the window bounds is considered deleted, even though the operation is not delete.

The reason that the bold/italic does not copy over is that we are writing the string to the dragging pasteboard as just a plain NSString. If you want the other settings to carry over you would need to write it as an NSAttributedString, and then on the drag source side of things you would need to interpret that NSAttributedString, for example using -attribute:atIndex:effectiveRange:.


Okay, thanks for the information.

The first and third responses are very clear. However, just to make sure I understand the second one, since we are working with objects within a document that can be deleted, it would then be responsibility of the application to track those deleted items, something like the mail client or iTunes? Whereas the actual OS Trash Can holds and tracks items that are being handed it by the OS, such as files?


Exactly. It’s up to the drag source to do the actual deletion in the case of dragging to the trash can – whatever that means for that particular drag source. In the case of the BigLetterView, deletion just means setting the string to be empty.