Swift 4: NSFilenamesPboardType not available. What to use instead for registerForDraggedTypes?

后端 未结 7 718
一向
一向 2020-12-28 08:11

After migrating to Swift4 the following code raise compile error:

public final class MediaItemView: NSView {

   public override init(frame frameRect: NSRect         


        
7条回答
  •  甜味超标
    2020-12-28 08:42

    I've solved backwards compatibility with this extension:

    extension NSPasteboard.PasteboardType {
    
        static let backwardsCompatibleFileURL: NSPasteboard.PasteboardType = {
    
                if #available(OSX 10.13, *) {
                    return NSPasteboard.PasteboardType.fileURL
                } else {
                    return NSPasteboard.PasteboardType(kUTTypeFileURL as String)
                }
    
        } ()
    
    }
    

    Which means you can use NSPasteboard.PasteboardType.backwardsCompatibleFileURL

提交回复
热议问题