I'm trying to use the following API in Swift: UIPasteboard: setItems(_:options:) , as suggested in this answer:
UIPasteboard.general.setItems([[kUTTypeUTF8PlainText as String: text]], options: [.expirationDate : Date(timeIntervalSinceNow: 10)])
However, it seems that the kUTTypeUTF8PlainText constant has been deprecated and I need to use the UniformTypeIdentifiers framework:
pasteboard.setItems([[String(UTType.plainText): string]],
options: [.expirationDate: Date(timeIntervalSinceNow: 120)])
However, the setItems: method accept only String type as the key, so I need to somehow convert the UTType.plainText to be of type String. How can I achieve this?
You should use the
identifierproperty (also note the equivalent type is calledutf8PlainText):As the documentation says:
And
UIPasteBoardis such an API.