SoFunction
Updated on 2025-04-11

Swift 3.0 clipboard code copy and cross-application paste implementation code

There is a requirement, click a button to copy a piece of content, then go to other applications and press and paste directly.

Implementation is as follows:

override func viewDidLoad() {
 ()

 // Do any additional setup after loading the view.
  = 
 
 //Paste in the application, this txt is used to test let txt = UITextField(frame: CGRect(x: 100, y: 100, width: 100, height: 33))
  = 
  = "shuru"
 (txt)

 
 //1. Test the clipboard testPasteBoard(str: "123")
 
 
 }

 
 /// Test the clipboard to realize the code copy content /// Conclusion: You can long press the input box and paste it in the application, and you can still do it outside the application. func testPasteBoard(str:String) {
 
 // Just these two sentences are realized let paste = 
  = str
 
 
 } 

After copying, you can paste it in and outside the current application.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.