Search code examples
iosswiftcopy-paste

How do I place a fixed string text Foo into a paste buffer?


I have some text that user will be able to paste later on into UITextField. How can I copy that text programmatically?


Solution

  • By from jtbandes's Answer

    • To Copy
    @IBAction fucn btnCopyClick(_ sender: UIButton)
    {   
        UIPasteboard.general.string = YourTextField.text!
    }
    
    • Paste
    let contentText = UIPasteboard.general.string