我正在嘗試在 Swift 中使用以下 API:UIPasteboard: setItems(_:options:) ,如this answer中所建議:
UIPasteboard.general.setItems([[kUTTypeUTF8PlainText as String: text]], options: [.expirationDate : Date(timeIntervalSinceNow: 10)])
但是,似乎該kUTTypeUTF8PlainText常量已被棄用,我需要使用UniformTypeIdentifiers框架:
pasteboard.setItems([[String(UTType.plainText): string]],
options: [.expirationDate: Date(timeIntervalSinceNow: 120)])
但是,該setItems:方法只接受Stringtype 作為鍵,所以我需要以某種方式將其轉換UTType.plainText為 type String。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
您應該使用該identifier屬性(另請注意等效型別稱為utf8PlainText):
UTType.utf8PlainText.identifier
正如檔案所說:
不使用 UTType 的 API 使用
StringorCFString來通過識別符號參考型別。
并且UIPasteBoard是這樣一個API。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/408268.html
標籤:
上一篇:出列多個符合相同協議的單元格
下一篇:swift中來自collectionView的NSInternalInconsistencyException錯誤
