Persisting a PKDrawing to iCloud

I have an App in which I am using NSPersistentCloudKitContainer to store user's drawings, and to have them in sync across multiple devices.

To store the drawings, I am using a "Binary Data" attribute in my Core Data entity. In this attribute I am saving the data representation of the drawing by using this API https://developer.apple.com/documentation/pencilkit/pkdrawing/3281878-datarepresentation

I have observed that for some drawings this data representation consumes a huge amount of data, and that generates synchronisation problems among devices.

Is there a better approach to persist PKDrawings without this problem?

Replies

CloudKit automatically turns your data into a CKAsset when it gets too big. I suppose the upload speed of your device's internet connection is the bottleneck here and there's not much we can do about it. If a drawing doesn't need to be edited anymore, it's probably best to turn it into an image and remove the drawing's data representation from your model object.
You probably want to explore a different serialization approach for PKDrawing than a transformable or binary data property.

Breaking the drawing up in to strokes for example, or a set of strokes modeled as a contribution to the drawing, would significantly reduce the serialization and sync overhead for large drawings.