iOS 11.x Swift 4
Trying to implement a custom class for using the new drop and drag protocol and need some super-coder help. I created this class.
import UIKit
import MobileCoreServices
class CustomClass: NSObject, NSItemProviderWriting, NSItemProviderReading {
var image2D:Data?
static var readableTypeIdentifiersForItemProvider = [kUTTypeData as String]
static func object(withItemProviderData data: Data, typeIdentifier: String) throws -> Self {
return try self.init(itemProviderData: data, typeidentifier: kUTTypeData as String)
}
required init(itemProviderData data: Data, typeidentifier: String) throws {
super.init()
image2D = data
}
static var writableTypeIdentifiersForItemProvider = [kUTTypeData as String]
func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping (Data?, Error?) -> Void) -> Progress? {
let data2E = image2D
completionHandler(data2E, nil)
return nil
}
}
It compiles, looks ok? Then I reference it with this call.
func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] {
let itemProvider = NSItemProvider(object: CustomClass)
let dragItem = UIDragItem(itemProvider: itemProvider)
return [dragItem]
}
And I got the error message ... Argument type 'CustomClass.Type' does not conform to expected type 'NSItemProviderWriting'...
But beyond that cannot seem to find any more clues here, there or anywhere as to how to move forward on this.
A side point I implemented one of these guys, it worked...
itemProvider.registerDataRepresentation(forTypeIdentifier: kUTTypeJPEG as String, visibility: .all)
And I implemented one of these guys, it worked too...
itemProvider.registerFileRepresentation(forTypeIdentifier: kUTTypeJPEG as String, fileOptions: [.openInPlace], visibility: .all)
So I am thinking, the code cannot be THAT wrong... surely...