8
votes

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

2

2 Answers

8
votes

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)
8
votes
import Foundation

import CoreData

import CloudKit

class Entity: NSManagedObject {

// MARK: - Properties

@NSManaged var recordID: CKRecordID?

// Additional properties here

}

Then change the Core Data attribute type to Transformable instead of String.