I've got a Multiplatform app with a SwiftUI view and this function:
In an extension of my controller I conform to the DropDelegate and implement performDrop(info:)
I've also typealias'ed the Image types.
Here's my implementation:
This compiles fine on iOS, tho on macOS I get the following errors:
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:
andInstance method 'canLoadObject(ofClass:)' requires that 'MPImage' (aka 'NSImage') conform to 'ObjectiveCBridgeable'
ObjectiveCBridgeable'Is this not the way to do drag and drop on macOS?Instance method 'loadObject(ofClass:completionHandler:)' requires that 'MPImage' (aka 'NSImage') conform to '