Finder URL解释

时间:2017-02-27 02:30:55

标签: swift macos drag-and-drop

在这个例程 - tableView validateDrop中,我需要了解返回的项目。返回项数组似乎是文件ID?

func tableView(tableView: NSTableView, validateDrop info: NSDraggingInfo, 
proposedRow row: Int, proposedDropOperation dropOperation: NSTableViewDropOperation) -> NSDragOperation {
    print("validate drop \(dropOperation)")
    if dropOperation == .Above {
        //get the file URLs from the pasteboard
        let pasteboard = info.draggingPasteboard()

        //list the file type UTIs we want to accept
        let options = [NSPasteboardURLReadingFileURLsOnlyKey : true,
                       NSPasteboardURLReadingContentsConformToTypesKey : [kUTTypeMovie as String]]
        let items = pasteboard.readObjectsForClasses([NSURL.classForCoder()],
                                                         options: options)
        if items!.count > 0 {
            for item in items! {
                print("item -> \(item)")
            }

            print("validate Above -> .Copy")
            return .Copy;

        } else {

            print("validate Above -> .Move")
            return .Move

        }
    }
    print("validate other -> .None")
    return .None
}

输出:

item -> file:///.file/id=6571367.34508463

在某些时候,我需要将其翻译为我可以使用的内容 - 典型的文件://格式化的URL。

1 个答案:

答案 0 :(得分:0)

po item.filePathURL
▿ Optional<NSURL>
  - Some : file:///Users/slashlos/Movies/Flight%20to%20Mars.m4v

我可能不会让用户查看