1

I'm trying to draw something in app with PencilKit. Now I want to export my drawings from my file, so I could open send it to other devices, and then open it(in format PKDrawing).

1 Answers1

1
var canvasView = PKCanvasView()
//user does drawing...
let data = canvasView.drawing.dataRepresentation()

data will be of type Data. You can then write that to a file (https://developer.apple.com/documentation/foundation/nsdata/1414800-write) and export it however you want.

For example, you could use ExportFilesAction: https://www.youtube.com/watch?v=iDseNgvdTpA

To load this data back into a PKDrawing, you can:

let drawing = try? PKDrawing(data: dataToLoad)
jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • Thank you! So i can load data format in PKDrawing, but can i create this type of dataset with .drawing inside. For example, in sample app there is File Notes.dataset with .drawing file there. – user14978817 Jan 12 '21 at 09:36
  • I’m sorry, I don’t understand what you’re asking. – jnpdx Jan 12 '21 at 15:38
  • Unfortunately the export files action example in the provided link no longer works due to, presumably, Apple's changes. – Marcy Mar 21 '23 at 20:19