Optimizing CKFetchRecordZoneChangesOperation to fetch desiredKeys

479 views Asked by At

In my CloudKit app, I create one zone in the private database where all the CKRecords are stored. The CKRecords can be of 10 different record types, and some of them can have CKAssets attached to them. I use CKFetchRecordZoneChangesOperation to find the record changes in this zone, and download them. I want to optimize the CKFetchRecordZoneChangesOperation so that I include only desiredKeys in the download, so I don't download the CKAsset at that time, but there doesn't seem to be any way to specify this per record type. Instead it seems like you can only specify desiredKeys on CKFetchRecordZoneChangesOptions, which is set on the zoneID.

So how can I specify 'desiredKeys' on my CKFetchRecordZoneChangesOperation fetch, considering there are different types of record types in that zone? Am I missing something simple here? The other (drastic) option I guess is to create a record zone for each record type, but I wouldn't want to go down that path if an alternative is possible.

Thanks.

1

There are 1 answers

0
Klaas On BEST ANSWER

The only option is to prefix your field names for each record type. This make it possible to specify the desired keys per record type.

https://developer.apple.com/reference/cloudkit/ckfetchrecordzonechangesoptions/1640472-desiredkeys states:

var desiredKeys: [String]?

...

Because the records you fetch can be of different types, the array should contain the merged set of all field names for the requested records and include at least one field name from each record type.

...

Your observation is true. You neither can fetch zone changes specific to a record type.