Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Copy Paste in Swift

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 577
    Comment on it

    Apple provides the UIPasteboard class which  enables the data to be shared within the app and with another app. To share data we can use pasteboards.


    Here is the code snippet depicting how copy and Paste functionality can be achieved in Swift using UIPasteBoards.
     

    To copy the text using pasteboard:
    1- Create the pasteboard object using general or shared system pasteboard

    let pasteBoard    = UIPasteboard.generalPasteboard();

     

    2- Use property ‘string’ to set the text to be copied. 

    pasteBoard.string = textTobeCopied; // Set your text to be copied here.

     

    To Print or fetch the text which was copied earlier :

    1- Create the pasteboard object using shared system.

    let pasteBoard    = UIPasteboard.generalPasteboard()

     

    2- use extension property ‘string’ of pasteboard to get the copied string.

    print(Text copied \(pasteBoard.string))

     

    Thanks for reading

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: