Swiftgram/TelegramUI/Pasteboard.swift
2019-04-23 21:35:00 +04:00

18 lines
674 B
Swift

import Foundation
import UIKit
import MobileCoreServices
public extension UIPasteboard {
func set(attributedString: NSAttributedString?) {
guard let attributedString = attributedString else {
return
}
do {
let rtf = try attributedString.data(from: NSMakeRange(0, attributedString.length), documentAttributes: [NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.rtf])
self.items = [[kUTTypeRTF as String: NSString(data: rtf, encoding: String.Encoding.utf8.rawValue)!, kUTTypeUTF8PlainText as String: attributedString.string]]
} catch {
}
}
}