I’m working in a App using Swift that includes PencilKit with a “canvasview” to take notes. Everything works fine, but I can’t find the way to “convert” de value returned by canvasView.drawing to String for uploaded it and storage into a database.
I can get a image and even a "base64EncodedString” but I need a way to send the “drawing” to a server and then load from it, and show in the canvasView.
I have tested to convert it into a json, but I can’t “deserialize” and convert it into a “drawing” again, when is loaded from the server hehe.
Thanks in advance
As far as I checked the doc, `PKDrawing` has an initilizer taking `Data`.
Does that not work?
If you prefer sending and receiving the data as Base-64, you can write an extension like this:
extension PKDrawing {
func base64EncodedString() -> String {
return dataRepresentation().base64EncodedString()
}
enum DecodingError: Error {
case decodingError
}
init(base64Encoded base64: String) throws {
guard let data = Data(base64Encoded: base64) else {
throw DecodingError.decodingError
}
try self.init(data: data)
}
}