Orphaning a CKAsset

I'm running into a problem in my attempt to clear CKAssets on the iCloud server. The documentation for CKAsset says:

If you no longer require an asset that’s on the server, you don’t delete it. Instead, orphan the asset by setting any fields that contain the asset to nil and then saving the record. CloudKit periodically deletes orphaned assets from the server.

I'm deleting image file assets which are properties on an ImageReference type (largeImage and thumbNailImage properties). When I delete an image, I am setting those properties to nil and sending the record for the ImageReference to iCloud using the async CKDatabase.modifyRecords method.

This always results in an error: <CKError 0x600000d92a60: "Asset File Not Found" (16/3002); "open error: 2 (No such file or directory)">

And of course the assets still appear in the CloudKit dashboard.

What is the proper way of orphaning the assets on the CloudKit server?

can you show some code?

Orphaning a CKAsset
 
 
Q