Search code examples
swiftcore-datacloudkit

Savings CloudKit RecordID to CoreData


I have a array of CloudKit records and want to store the record ID in to core data so when i query the cloud again i do not pull down the same records. I just do a NSpRedicate not contain the records from core data.

However, getting an error, how do I save a record ID to core data.. Think it is a Type issue.

Current Code:

 coreData.recordRecordID = self.cloudKitRecords[0].recordID as? String

Current getting the error that CKRecord as String always fails, which I am not surprised. Need to be able to save the recordID then get the recordID from core data.

Thanks


Solution

  • You can get the id like this:

    coreData.recordRecordID = self.cloudKitRecords[0].recordID.recordName
    

    It will then be a string. If you want to make a CKRecordID from that, then you can create one using

    var myID = = CKRecordID(recordName: yourStringID)