しばらく苦労したので、この問題への回答を投稿すると思いました。このコードは promise を処理し、ドロップされたメールをユーザー フォルダー内の Drop Stuff というフォルダーに単純にコピーします。また、任意のファイルでも機能し、アドレス帳やリマインダーなどの他のアプリでも機能するようです。複数のファイル (またはメール メッセージ) のコピーにはまだ機能しません。
import Cocoa
class DropArea: NSImageView, NSDraggingDestination
{
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
}
required init?(coder: NSCoder)
{
let types = [NSFilenamesPboardType, NSURLPboardType, NSPasteboardTypeTIFF, NSFilesPromisePboardType]
super.init(coder: coder)
registerForDraggedTypes(types)
}
override func draggingEntered(sender: NSDraggingInfo) -> NSDragOperation
{
return .Copy
}
override func performDragOperation(sender: NSDraggingInfo) -> Bool
{
var error: NSError?
var folderPath = NSHomeDirectory()+"/Drop Stuff/"
if (!NSFileManager.defaultManager().fileExistsAtPath(folderPath))
{
NSFileManager.defaultManager().createDirectoryAtPath(folderPath, withIntermediateDirectories: true, attributes: nil, error: &error)
}
var folderURL = NSURL(fileURLWithPath: folderPath)
var f = sender.namesOfPromisedFilesDroppedAtDestination(folderURL!)
println("Copied to \(folderPath)")
return true
}
}
もちろん、このコードを改善するための提案は大歓迎です:-)