Public Database Cloud Kit Missing Queryables

Hi there,

Following this tutorial for my own project: https://developer.apple.com/videos/play/wwdc2020/10650/?time=319

I noticed that I cannot mark modifiedAt index as queriable. It doesn't appear in a list, and I heard that it was renamed to modifiedTimestamp (can someone confirm?)

Although I've managed to upload records to the public DB, my fetching has been unsuccessful. I'm getting this error:

CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate finishedAutomatedRequestWithResult:](3372): Finished request '<NSCloudKitMirroringExportRequest: 0x600000eb6df0> 33AA10FE-C31F-44BB-A693-D3DC06604D18' with result: <NSCloudKitMirroringResult: 0x6000023ee790> storeIdentifier: 65A47C2C-8591-4404-B39C-44635142C32E success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134406 "Request '33AA10FE-C31F-44BB-A693-D3DC06604D18' was aborted because the mirroring delegate never successfully initialized due to error: <CKError 0x6000023ee670: "Invalid Arguments" (12/2016); server message = "Field '___modTime' is not marked sortable"; op = A78A2D1EA27AD7B2; uuid = 88F346ED-96BB-4607-B764-957C313B71C2; container ID = "iCloud.tchapman.test2">" UserInfo={NSLocalizedFailureReason=Request '33AA10FE-C31F-44BB-A693-D3DC06604D18' was aborted because the mirroring delegate never successfully initialized due to error: <CKError 0x6000023ee670: "Invalid Arguments" (12/2016); server message = "Field '___modTime' is not marked sortable"; op = A78A2D1EA27AD7B2; uuid = 88F346ED-96BB-4607-B764-957C313B71C2; container ID = "iCloud.tchapman.test2">}

I don't know what this __modTime field is, but is it related to the missing modifiedAt index?

I'll also provide my container init code for reference:

            let description = NSPersistentStoreDescription(url: storeURL)
            description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.tchapman.test2")
            
            // MARK: Public Description
            let publicStoreURL = description.url!.deletingLastPathComponent().appendingPathComponent("AppleCloset-public2.sqlite")
            let publicDescription = NSPersistentStoreDescription(url: publicStoreURL)
            publicDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
            publicDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
            let publicOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: description.cloudKitContainerOptions!.containerIdentifier)
            publicOptions.databaseScope = .public
            publicDescription.cloudKitContainerOptions = publicOptions
            
            container.persistentStoreDescriptions = [publicDescription]

Make sure that you first create an index for the timestamp. Add the queryable index if you plan to use it in your predicate, such as 'created|modified after Tuesday'. Add the sortable index if you plan to use the property as a sort descriptor. Finally, if you're testing in production, make sure that your indices were pushed to production! This is never a fun thing to debug. Been there done that.

I'm doing a manual synchronization where I 'fetch modified since last cursor'. Regarding the name of the properties, if you're fetching all properties, you can use the debugger to inspect the system field names.