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

后端 未结 7 686
一向
一向 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:44

    Swift4, Swift5:

    Well part temporary workaround but working for Swift4/5:

    var chromeType: NSPasteboard.PasteboardType { return NSPasteboard.PasteboardType.init(rawValue: "org.chromium.drag-dummy-type") }
    var finderNode: NSPasteboard.PasteboardType { return NSPasteboard.PasteboardType.init(rawValue: "com.apple.finder.node") }
    var fileURLs: NSPasteboard.PasteboardType { return NSPasteboard.PasteboardType.init(rawValue: "NSFilenamesPboardType") }
    var webarchive: NSPasteboard.PasteboardType { return NSPasteboard.PasteboardType.init(rawValue: "com.apple.webarchive") }
    

    then aggregate as

    var acceptableTypes: Set { return [.URL, .fileURL, .pdf, .png, .rtf, .rtfd, .tiff, finderNode, webarchive] }
    

    then use in view did load method:

    //  Intercept drags
    registerForDraggedTypes(Array(acceptableTypes))
    

提交回复
热议问题