Saving images & video to Core Data (with CloudKit)

Hello

What would be the best and most efficient way to save photos and videos using Core Data knowing that they will be synced using CloudKit.

Thanks

Don't save videos or even images directly in CoreData. Just save links.

See extensive discussion in this 5 years old thread, which just explains why and how.

https://developer.apple.com/forums/thread/63330

Syncing large data files in CoreData<->CloudKit is particularly challenging. If you just store data in Binary Data attributes, that get converted into CKAssets, then fetching and modifying those CKRecords can take a long time, and potentially timeout, particularly if the user backgrounds the app and it gets suspended. To my knowledge, NSPersistentCloudKitContainer does use background tasks for syncing, but these aren't the same as long-lived operations, which are handled outside of the app.

I've been pondering these issues for a while now, and have been working on an update to an open-source sync engine called CloudCore, with support for Cacheable Assets. Its a bit complex to establish your schema and code, but once done, large files you associate with CoreData managed objects are uploaded and downloaded using long-lived operations. The feature isn't quite ready yet, still doing some real-world testing, but you can see the progress here… https://github.com/deeje/CloudCore/pull/28 and feel free to check out the branch here… https://github.com/deeje/CloudCore/tree/feature/Cacheable

Saving images &amp; video to Core Data (with CloudKit)
 
 
Q