Latest 1.0.3
Homepage https://github.com/cupnoodle/ADragDropView
License MIT
Platforms osx 10.12

Add a Drag and drop view (swift) for your macOS app easily

I used this in my mac app, PDF Page Number + Watermark

Demo

Requirements

  • macOS 10.12+
  • Xcode 9.4.1+
  • Swift 4.1+

Install

Manual

Copy the ADragDropView.swift and NSDraggingInfo+FilePathURL.swift inside the ADragDropView folder to your project.

CocoaPods

pod 'ADragDropView'

On the top of view controller, add

import ADragDropView

Usage

Run the ADragDropViewExample target in Xcode to try the demo.

Drag and drop a Custom View to your view controller in Interface Builder, set its class to ADragDropView and create an IBOutlet for it.

custom view

custom class

Set delegate (usually to the view controller), dragDropView.delegate = self .

Set the allowed file extensions: dragDropView.acceptedFileExtensions = ["png", "jpg", "jpeg", "gif"] .

Implement the two delegate methods to handle dropped file(s) :

extension ViewController: ADragDropViewDelegate {
    // when one file is dropped
    func dragDropView(_ dragDropView: ADragDropView, droppedFileWithURL URL: URL) {

        // action to do when the file is dropped
    }

    // when multiple files are dropped
    func dragDropView(_ dragDropView: ADragDropView, droppedFilesWithURLs URLs: [URL]) {

       // action to do when the files are dropped
    }
}

Latest podspec

{
    "name": "ADragDropView",
    "version": "1.0.3",
    "summary": "Add a Drag and drop view (swift) for your macOS app easily",
    "description": "Add a file drag and drop view (swift) to your macOS app easily, works with sandboxed app as well",
    "homepage": "https://github.com/cupnoodle/ADragDropView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "Axel Kee",
    "social_media_url": "http://twitter.com/soulchildpls",
    "swift_version": "4.1",
    "platforms": {
        "osx": "10.12"
    },
    "source": {
        "git": "https://github.com/cupnoodle/ADragDropView.git",
        "tag": "1.0.3"
    },
    "source_files": "ADragDropView/**/*.swift"
}

Pin It on Pinterest

Share This