ぜのぜ

しりとりしようぜのぜのぜのぜ

Swiftでクリップボードに文字列をコピーする(AppKitの場合

Appleとしてはペーストボードと呼びたいらしい.

NSPasteboardを使う.なにか書き込む前にclearContents ()を呼ぶのがポイント.なぜならドキュメントにそう書いてあるから.

Clears the existing contents of the pasteboard, preparing it for new contents. This is the first step in providing data on the pasteboard.

let pboard = NSPasteboard.general
pboard.clearContents()
pboard.setString("hoge", forType: .string)

眠いので終わり

--- 追記ここから 2021/08/12 21:14

iOSアプリというかUIKitのときはUIPasteboardを使う. つっこみがあったので追記

--- 追記終わり