【问题标题】:Finder URL interpretationFinder URL 解释
【发布时间】:2017-02-27 02:30:55
【问题描述】:

在这个例程——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

在某些时候,我需要将其转换为我可以使用的内容 - 一个典型的 file:// 格式的 URL。

【问题讨论】:

    标签: swift macos drag-and-drop


    【解决方案1】:

    呵呵

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

    我可能不会为用户查看而转义

    【讨论】:

      猜你喜欢
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      • 2017-01-11
      • 1970-01-01
      相关资源
      最近更新 更多