I've got a Multiplatform app with a SwiftUI view and this function:
.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.
#if os(macOS)
public typealias MPImage = NSImage
#else
public typealias MPImage = UIImage
#endif
Here's my implementation:
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?
1
0
2.1k