In Swift, you can use the URL standard to get a valid path from the reference URL. So, in Swift 4 - to get the file name from a drag-and-drop file, you would do something like ...
let fileType = NSPasteboard.PasteboardType (kUTTypeFileURL as String)
extension NSPasteboardItem {
func fileURL ()->URL? {
if let refURL = self.string(forType: fileType) {
return URL (fileURLWithPath: refURL).standardized
}
return nil
}
}
source
share