Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 296
TravelNVal Avatar asked Dec 21 '15 23:12

TravelNVal


2 Answers

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)
like image 121
Edwin Vermeer Avatar answered Jan 02 '23 03:01

Edwin Vermeer


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.

like image 41
shawnynicole Avatar answered Jan 02 '23 05:01

shawnynicole