How to Drag and Drop Images in SwiftUI on macOS

I've got a Multiplatform app with a SwiftUI view and this function:

Code Block swift
.onDrop(of: [.image], delegate: myController)


In an extension of my controller I conform to the DropDelegate and implement performDrop(info:)

I've also typealias'ed the Image types.

Code Block swift
#if os(macOS)
public typealias MPImage = NSImage
#else
public typealias MPImage = UIImage
#endif


Here's my implementation:

Code Block swift
guard info.hasItemsConforming(to: [.image]) else { return false }
let items: [NSItemProvider] = info.itemProviders(for: [.image])
guard let item: NSItemProvider = items.first else { return false }
guard item.canLoadObject(ofClass: MPImage.self) else { return false }
item.loadObject(ofClass: MPImage.self) { (reading, error) in
guard error == nil else { return }
guard let image: MPImage = reading as? MPImage else { return }
self.didLoad(image: image)
}


This compiles fine on iOS, tho on macOS I get the following errors:

Instance method 'canLoadObject(ofClass:)' requires that 'MPImage' (aka 'NSImage') conform to 'ObjectiveCBridgeable'

and

Instance method 'loadObject(ofClass:completionHandler:)' requires that 'MPImage' (aka 'NSImage') conform to '

ObjectiveCBridgeable'Is this not the way to do drag and drop on macOS?


I am seeing this error too. Did you ever find a solution to this?

How to Drag and Drop Images in SwiftUI on macOS
 
 
Q