I've got a SwiftUI app with the onDrop method on my View like this:
In an extension of my controller I conform to the DropDelegate and implement performDrop(info:)
Here's my implementation:
The code compiles fine on iOS (tho not on macOS, see link)
https://developer.apple.com/forums/thread/653934
So when I run the app on iOS, and drag an image from Photos and drop it on my app I get the following error:
Code Block .onDrop(of: [.image], delegate: myController)
In an extension of my controller I conform to the DropDelegate and implement performDrop(info:)
Here's my implementation:
Code Block 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) }
The code compiles fine on iOS (tho not on macOS, see link)
https://developer.apple.com/forums/thread/653934
So when I run the app on iOS, and drag an image from Photos and drop it on my app I get the following error:
MyApp perform drop failed: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg" UserInfo={NSLocalizedDescription=Cannot load representation of type public.jpeg, NSUnderlyingError=0x283fa15f0 {Error Domain=NSCocoaErrorDomain Code=260 "The file “DAE533E7-2918-465E-9F3C-502B8DEC78BA.jpeg” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///var/tmp/com.apple.DragUI.druid/.com.apple.DragUI.BDfAeP/DAE533E7-2918-465E-9F3C-502B8DEC78BA.jpeg, NSFilePath=/var/tmp/com.apple.DragUI.druid/.com.apple.DragUI.BDfAeP/DAE533E7-2918-465E-9F3C-502B8DEC78BA.jpeg, NSUnderlyingError=0x283f4b8a0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}}}