Saving UIDocument to CoreData

I have a note-taking app that enables persistence of data using CoreData.

I would like to be able to attach a document to a note and it to be stored persistently, so that when the user taps the attachment they are provided with an action sheet to open in another app, share, copy etc...

Additionally, I would like this to work cross device using CloudKit so I can't just store a bookmark or url using bookmarkData(options:includingResourceValuesForKeys:relativeTo:).

I have figured that using UIDocument would be the best way to handle the file but I'm not sure how to save this as an attribute to a core data entity or even if this is the best way to go about this.

It seems like a common premise: saving a file attachment.

Many thanks.

Replies

I would sae the document to a file, and save the URL in CoreData if needed.

You may read this technical discussion to get details:

h t t p s : / / w w w.swiftdevjournal. com/saving-data-in-a-swift-app/