How to make simple NSItemProvider in Swift

Issue #728

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
NSItemProvider(object: StringProvider(string: string))

class StringProvider: NSObject, NSItemProviderWriting {
let string: String
init(string: String) {
self.string = string
super.init()
}

static var writableTypeIdentifiersForItemProvider: [String] {
return [(kUTTypeData) as String]
}

func loadData(
withTypeIdentifier typeIdentifier: String,
forItemProviderCompletionHandler completionHandler: @escaping (Data?, Error?) -> Void
) -> Progress? {
let data = string.data(using: .utf8)
completionHandler(data, nil)
return Progress(totalUnitCount: 100)
}
}

Comments