What is the best way to copy text to the iPhone's clipboard in your application?
Their docs are sketchy and have way more features than what I want... I just want to set a string as the users clipboard.
samvermette
Although the accepted answer is a good walkthrough of how UIPasteboard
works, I figured I'd post the relevant snippet right here for everyone's convenience:
OBJ-C
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = @"paste me somewhere";
Swift 2.2
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
Swift 3+:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"
Mojtabye
Swift 2.2 :
let pasteBoard = UIPasteboard.generalPasteboard()
pasteBoard.string = "Paste Me !"
Swift 3:
let pasteBoard = UIPasteboard.general
pasteBoard.string = "Paste me!"
来源:https://stackoverflow.com/questions/1479468/copy-text-to-clipboard-with-ios