0

I want to copy an image to the UIPasteboard and paste it e.g. Into WhatsApp.

But this is not working.

If I test it on my device, the pasteboard is not set (old copy content) and ff I check it with the debugger, po pasteboard always prints << uninitialized >>.

My source (data is set):

    let data              = UIImagePNGRepresentation(image)
    let pasteboard        = UIPasteboard.generalPasteboard()
    pasteboard.persistent = true
    pasteboard.setData(data!, forPasteboardType: "public.png")
JAL
  • 41,701
  • 23
  • 172
  • 300
Tobonaut
  • 2,245
  • 2
  • 26
  • 39
  • 1
    If you're checking the description of `pasteboard`, make sure you're checking its value the line after it is assigned. Otherwise it will return `<< uninitialized >>` because its value hasn't been assigned yet. – JAL Feb 01 '16 at 17:59
  • Thanks for opening my eyes. This was the answer. :) – Tobonaut Feb 01 '16 at 18:23
  • 1
    I have added the comment as an answer. Feel free to mark it as accepted if it has helped you. – JAL Feb 01 '16 at 18:24

1 Answers1

1

If you're checking the description of pasteboard, make sure you're checking its value the line after it is assigned. Otherwise it will return << uninitialized >> because its value hasn't been assigned yet.

JAL
  • 41,701
  • 23
  • 172
  • 300